fix: use targetFilter in puppeteer.launch (#8774)

Drive-by: adds Symbol.toStringTag to Target to simplify
debugging.

Closes #8772
This commit is contained in:
Alex Rudenko 2022-08-11 11:15:00 +02:00 committed by GitHub
parent b4176029d9
commit ee2540baef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 2 deletions

View File

@ -135,6 +135,13 @@ export class Target {
return this.#sessionFactory();
}
/**
* @internal
*/
get [Symbol.toStringTag](): string {
return JSON.stringify(this.#targetInfo, null, 2);
}
/**
* @internal
*/

View File

@ -161,7 +161,8 @@ export class ChromeLauncher implements ProductLauncher {
ignoreHTTPSErrors,
defaultViewport,
runner.proc,
runner.close.bind(runner)
runner.close.bind(runner),
options.targetFilter
);
} catch (error) {
runner.kill();

View File

@ -158,7 +158,8 @@ export class FirefoxLauncher implements ProductLauncher {
ignoreHTTPSErrors,
defaultViewport,
runner.proc,
runner.close.bind(runner)
runner.close.bind(runner),
options.targetFilter
);
} catch (error) {
runner.kill();

View File

@ -753,6 +753,29 @@ describe('Launcher specs', function () {
await page.close();
await browser.close();
});
it('should support targetFilter option in puppeteer.launch', async () => {
const {puppeteer, defaultBrowserOptions} = getTestState();
const browser = await puppeteer.launch({
...defaultBrowserOptions,
targetFilter: target => {
return target.type !== 'page';
},
waitForInitialPage: false,
});
try {
const targets = browser.targets();
expect(targets.length).toEqual(1);
expect(
targets.find(target => {
return target.type() === 'page';
})
).toBeUndefined();
} finally {
await browser.close();
}
});
// @see https://github.com/puppeteer/puppeteer/issues/4197
itFailsFirefox('should support targetFilter option', async () => {
const {server, puppeteer, defaultBrowserOptions} = getTestState();