mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: use targetFilter in puppeteer.launch (#8774)
Drive-by: adds Symbol.toStringTag to Target to simplify debugging. Closes #8772
This commit is contained in:
parent
b4176029d9
commit
ee2540baef
@ -135,6 +135,13 @@ export class Target {
|
|||||||
return this.#sessionFactory();
|
return this.#sessionFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
get [Symbol.toStringTag](): string {
|
||||||
|
return JSON.stringify(this.#targetInfo, null, 2);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
|
@ -161,7 +161,8 @@ export class ChromeLauncher implements ProductLauncher {
|
|||||||
ignoreHTTPSErrors,
|
ignoreHTTPSErrors,
|
||||||
defaultViewport,
|
defaultViewport,
|
||||||
runner.proc,
|
runner.proc,
|
||||||
runner.close.bind(runner)
|
runner.close.bind(runner),
|
||||||
|
options.targetFilter
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
runner.kill();
|
runner.kill();
|
||||||
|
@ -158,7 +158,8 @@ export class FirefoxLauncher implements ProductLauncher {
|
|||||||
ignoreHTTPSErrors,
|
ignoreHTTPSErrors,
|
||||||
defaultViewport,
|
defaultViewport,
|
||||||
runner.proc,
|
runner.proc,
|
||||||
runner.close.bind(runner)
|
runner.close.bind(runner),
|
||||||
|
options.targetFilter
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
runner.kill();
|
runner.kill();
|
||||||
|
@ -753,6 +753,29 @@ describe('Launcher specs', function () {
|
|||||||
await page.close();
|
await page.close();
|
||||||
await browser.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
|
// @see https://github.com/puppeteer/puppeteer/issues/4197
|
||||||
itFailsFirefox('should support targetFilter option', async () => {
|
itFailsFirefox('should support targetFilter option', async () => {
|
||||||
const {server, puppeteer, defaultBrowserOptions} = getTestState();
|
const {server, puppeteer, defaultBrowserOptions} = getTestState();
|
||||||
|
Loading…
Reference in New Issue
Block a user