fix: make targetFilter synchronous (#7203)

This commit is contained in:
Jan Scheffler 2021-05-05 09:50:50 +02:00 committed by GitHub
parent 8816645c71
commit bcc85a0969
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -516,7 +516,7 @@ Clears all registered handlers.
- `slowMo` <[number]> Slows down Puppeteer operations by the specified amount of milliseconds. Useful so that you can see what is going on. - `slowMo` <[number]> Slows down Puppeteer operations by the specified amount of milliseconds. Useful so that you can see what is going on.
- `transport` <[ConnectionTransport]> **Experimental** Specify a custom transport object for Puppeteer to use. - `transport` <[ConnectionTransport]> **Experimental** Specify a custom transport object for Puppeteer to use.
- `product` <[string]> Possible values are: `chrome`, `firefox`. Defaults to `chrome`. - `product` <[string]> Possible values are: `chrome`, `firefox`. Defaults to `chrome`.
- `targetFilter` <?[function]\([Protocol.Target.TargetInfo]\):[Promise]<[boolean]>|[boolean]> Use this function to decide if Puppeteer should connect to the given target. If a `targetFilter` is provided, Puppeteer only connects to targets for which `targetFilter` returns `true`. By default, Puppeteer connects to all available targets. - `targetFilter` <?[function]\([Protocol.Target.TargetInfo]\):[boolean]> Use this function to decide if Puppeteer should connect to the given target. If a `targetFilter` is provided, Puppeteer only connects to targets for which `targetFilter` returns `true`. By default, Puppeteer connects to all available targets.
- returns: <[Promise]<[Browser]>> - returns: <[Promise]<[Browser]>>
This methods attaches Puppeteer to an existing browser instance. This methods attaches Puppeteer to an existing browser instance.
@ -624,7 +624,7 @@ try {
- `devtools` <[boolean]> Whether to auto-open a DevTools panel for each tab. If this option is `true`, the `headless` option will be set `false`. - `devtools` <[boolean]> Whether to auto-open a DevTools panel for each tab. If this option is `true`, the `headless` option will be set `false`.
- `pipe` <[boolean]> Connects to the browser over a pipe instead of a WebSocket. Defaults to `false`. - `pipe` <[boolean]> Connects to the browser over a pipe instead of a WebSocket. Defaults to `false`.
- `extraPrefsFirefox` <[Object]> Additional [preferences](https://developer.mozilla.org/en-US/docs/Mozilla/Preferences/Preference_reference) that can be passed to Firefox (see `PUPPETEER_PRODUCT`) - `extraPrefsFirefox` <[Object]> Additional [preferences](https://developer.mozilla.org/en-US/docs/Mozilla/Preferences/Preference_reference) that can be passed to Firefox (see `PUPPETEER_PRODUCT`)
- `targetFilter` <?[function]\([Protocol.Target.TargetInfo]\):[Promise]<[boolean]>|[boolean]> Use this function to decide if Puppeteer should connect to the given target. If a `targetFilter` is provided, Puppeteer only connects to targets for which `targetFilter` returns `true`. By default, Puppeteer connects to all available targets. - `targetFilter` <?[function]\([Protocol.Target.TargetInfo]\):[boolean]> Use this function to decide if Puppeteer should connect to the given target. If a `targetFilter` is provided, Puppeteer only connects to targets for which `targetFilter` returns `true`. By default, Puppeteer connects to all available targets.
- returns: <[Promise]<[Browser]>> Promise which resolves to browser instance. - returns: <[Promise]<[Browser]>> Promise which resolves to browser instance.
You can use `ignoreDefaultArgs` to filter out `--mute-audio` from default arguments: You can use `ignoreDefaultArgs` to filter out `--mute-audio` from default arguments:

View File

@ -34,7 +34,7 @@ export type BrowserCloseCallback = () => Promise<void> | void;
*/ */
export type TargetFilterCallback = ( export type TargetFilterCallback = (
target: Protocol.Target.TargetInfo target: Protocol.Target.TargetInfo
) => Promise<boolean> | boolean; ) => boolean;
const WEB_PERMISSION_TO_PROTOCOL_PERMISSION = new Map< const WEB_PERMISSION_TO_PROTOCOL_PERMISSION = new Map<
Permission, Permission,
@ -342,7 +342,7 @@ export class Browser extends EventEmitter {
? this._contexts.get(browserContextId) ? this._contexts.get(browserContextId)
: this._defaultContext; : this._defaultContext;
const shouldAttachToTarget = await this._targetFilterCallback(targetInfo); const shouldAttachToTarget = this._targetFilterCallback(targetInfo);
if (!shouldAttachToTarget) { if (!shouldAttachToTarget) {
return; return;
} }