Skip to content

Commit

Permalink
fix: use targetFilter in puppeteer.launch (#8774)
Browse files Browse the repository at this point in the history
Drive-by: adds Symbol.toStringTag to Target to simplify
debugging.

Closes #8772
  • Loading branch information
OrKoN committed Aug 11, 2022
1 parent b417602 commit ee2540b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/common/Target.ts
Expand Up @@ -135,6 +135,13 @@ export class Target {
return this.#sessionFactory();
}

/**
* @internal
*/
get [Symbol.toStringTag](): string {
return JSON.stringify(this.#targetInfo, null, 2);
}

/**
* @internal
*/
Expand Down
3 changes: 2 additions & 1 deletion src/node/ChromeLauncher.ts
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/node/FirefoxLauncher.ts
Expand Up @@ -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();
Expand Down
23 changes: 23 additions & 0 deletions test/src/launcher.spec.ts
Expand Up @@ -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();
Expand Down

0 comments on commit ee2540b

Please sign in to comment.