fix: make sure there is a check for targets when timeout=0 (#8765)
Previously, if timeout is falsy, the targets would only be checked if a browser-level event fires which lead to a race: if the events arrived before waiting for a target, the promise would never resolve. Fixes #8763
This commit is contained in:
parent
b5064b7b8b
commit
c23cdb73a7
@ -649,10 +649,10 @@ export class Browser extends EventEmitter {
|
|||||||
this.on(BrowserEmittedEvents.TargetCreated, check);
|
this.on(BrowserEmittedEvents.TargetCreated, check);
|
||||||
this.on(BrowserEmittedEvents.TargetChanged, check);
|
this.on(BrowserEmittedEvents.TargetChanged, check);
|
||||||
try {
|
try {
|
||||||
|
this.targets().forEach(check);
|
||||||
if (!timeout) {
|
if (!timeout) {
|
||||||
return await targetPromise;
|
return await targetPromise;
|
||||||
}
|
}
|
||||||
this.targets().forEach(check);
|
|
||||||
return await waitWithTimeout(targetPromise, 'target', timeout);
|
return await waitWithTimeout(targetPromise, 'target', timeout);
|
||||||
} finally {
|
} finally {
|
||||||
this.off(BrowserEmittedEvents.TargetCreated, check);
|
this.off(BrowserEmittedEvents.TargetCreated, check);
|
||||||
|
@ -543,6 +543,14 @@ describe('Launcher specs', function () {
|
|||||||
});
|
});
|
||||||
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
|
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
|
||||||
});
|
});
|
||||||
|
it('should work with timeout = 0', async () => {
|
||||||
|
const {puppeteer, defaultBrowserOptions} = getTestState();
|
||||||
|
const options = Object.assign({}, defaultBrowserOptions, {
|
||||||
|
timeout: 0,
|
||||||
|
});
|
||||||
|
const browser = await puppeteer.launch(options);
|
||||||
|
await browser.close();
|
||||||
|
});
|
||||||
it('should set the default viewport', async () => {
|
it('should set the default viewport', async () => {
|
||||||
const {puppeteer, defaultBrowserOptions} = getTestState();
|
const {puppeteer, defaultBrowserOptions} = getTestState();
|
||||||
const options = Object.assign({}, defaultBrowserOptions, {
|
const options = Object.assign({}, defaultBrowserOptions, {
|
||||||
|
Loading…
Reference in New Issue
Block a user