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:
Alex Rudenko 2022-08-10 15:49:59 +02:00 committed by GitHub
parent b5064b7b8b
commit c23cdb73a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -649,10 +649,10 @@ export class Browser extends EventEmitter {
this.on(BrowserEmittedEvents.TargetCreated, check);
this.on(BrowserEmittedEvents.TargetChanged, check);
try {
this.targets().forEach(check);
if (!timeout) {
return await targetPromise;
}
this.targets().forEach(check);
return await waitWithTimeout(targetPromise, 'target', timeout);
} finally {
this.off(BrowserEmittedEvents.TargetCreated, check);

View File

@ -543,6 +543,14 @@ describe('Launcher specs', function () {
});
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 () => {
const {puppeteer, defaultBrowserOptions} = getTestState();
const options = Object.assign({}, defaultBrowserOptions, {