UNPKG

automation-extra-plugin

Version:

Base class for automation-extra plugins (supports Playwright and Puppeteer).

777 lines (496 loc) 26.5 kB
# automation-extra-plugin [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/berstend/puppeteer-extra/Test/master)](https://github.com/berstend/puppeteer-extra/actions) [![Discord](https://img.shields.io/discord/737009125862408274)](http://scraping-chat.cf) [![npm](https://img.shields.io/npm/v/automation-extra-plugin.svg)](https://www.npmjs.com/package/automation-extra-plugin) > Base class to develop plugins for [automation-extra]. ## Installation ```bash yarn add automation-extra-plugin ``` <details> <summary>Changelog</summary> - v4.1 - Initial public release </details> ## Features - Supports [playwright-extra] as well as [puppeteer-extra] - Uses lifecycle events to hook into Puppeteer & Playwright execution - Ships with `this.env` and type guards to make multi-browser, multi-driver plugin development a breeze - Written in TypeScript (which means helpful auto-complete even if you're writing your plugins in JS) - Successor to `puppeteer-extra-plugin`, which only supports Puppeteer ## Example ```js const { AutomationExtraPlugin } = require('automation-extra-plugin') class DemoPlugin extends AutomationExtraPlugin { constructor(opts = {}) { super(opts) } static get id() { return 'demo' } async beforeLaunch(options) { // Modify launch options options.headless = false } async onBrowser(browser) { // Become aware of browser launch/connect console.log('onBrowser:', { driverName: this.env.driverName, browserName: this.env.browserName, }) } async onPageCreated(page) { // Hook into page events console.log('Page created:', page.url()) page.on('load', () => { console.log('Page loaded', page.url()) }) // Use a shim which unifies page.evaluateOnNewDocument and page.addInitScript this.shim(page).addScript(() => { navigator.alice = 'bob' }) } } const demo = new DemoPlugin() ``` Use the plugin with Puppeteer: ```js const puppeteer = require('puppeteer-extra') puppeteer.use(demo) // that's it :-) puppeteer.launch({ headless: true }).then(async (browser) => { const page = await browser.newPage() await page.goto('https://example.com', { waitUntil: 'load' }) const alice = await page.evaluate(() => navigator.alice) console.log(alice) // ==> bob await browser.close() }) ``` Use the same plugin with Playwright (chromium and webkit are supported as well): ```js const { firefox } = require('playwright-extra') firefox.use(demo) // that's it :-) firefox.launch({ headless: true }).then(async (browser) => { // ... same code as above }) ``` ## Contributing If you're interested in releasing your plugin under the `@extra` organization please reach out to us through an issue or on our discord server. :-) ## API <!-- Documentation is auto-generated by a custom fork of documentation.js More info: https://github.com/berstend/documentation-markdown-themes/wiki#documentationjs-with-markdown-theme-support Update this documentation by updating the source code. --> #### Table of Contents - [class: PluginLifecycleMethods](#class-pluginlifecyclemethods) - [.onPluginRegistered()](#onpluginregistered) - [.beforeLaunch(options)](#beforelaunchoptions) - [.afterLaunch(browser, launchContext)](#afterlaunchbrowser-launchcontext) - [.beforeConnect(options)](#beforeconnectoptions) - [.afterConnect(browser, launchContext)](#afterconnectbrowser-launchcontext) - [.onBrowser(browser, launchContext)](#onbrowserbrowser-launchcontext) - [.beforeContext(options, browser)](#beforecontextoptions-browser) - [.onContextCreated(context, options)](#oncontextcreatedcontext-options) - [.onPageCreated(page)](#onpagecreatedpage) - [.onPageClose(page)](#onpageclosepage) - [.onContextClose(context)](#oncontextclosecontext) - [.onDisconnected(browser)](#ondisconnectedbrowser) - [class: AutomationExtraPlugin](#class-automationextraplugin) - [.env](#env) - [.shim(page)](#shimpage) - [.defaults](#defaults) - [.requirements](#requirements) - [.filter](#filter) - [.dependencies](#dependencies) - [.plugins](#plugins) - [.opts](#opts) - [.debug](#debug) - [.id](#id) - [class: TypeGuards](#class-typeguards) - [.isPage(obj)](#ispageobj) - [.isBrowser(obj)](#isbrowserobj) - [.isPuppeteerPage(obj)](#ispuppeteerpageobj) - [.isPuppeteerBrowser(obj)](#ispuppeteerbrowserobj) - [.isPuppeteerBrowserContext(obj)](#ispuppeteerbrowsercontextobj) - [.isPlaywrightPage(obj)](#isplaywrightpageobj) - [.isPlaywrightBrowser(obj)](#isplaywrightbrowserobj) - [.isPlaywrightBrowserContext(obj)](#isplaywrightbrowsercontextobj) - [class: LauncherEnv](#class-launcherenv) - [.driverName](#drivername) - [.browserName](#browsername) - [.isPuppeteer](#ispuppeteer) - [.isPlaywright](#isplaywright) - [.isChromium](#ischromium) - [.isFirefox](#isfirefox) - [.isWebkit](#iswebkit) - [.isBrowserKnown](#isbrowserknown) - [class: PageShim](#class-pageshim) - [.addScript(script, arg?)](#addscriptscript-arg) ### class: [PluginLifecycleMethods](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L74-L241) Plugin lifecycle methods used by AutomationExtraPlugin. These are hooking into Playwright/Puppeteer events and are meant to be overriden on a per-need basis in your own plugin extending AutomationExtraPlugin. --- #### .[onPluginRegistered()](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L78-L78) Returns: **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;void>** After the plugin has been registered, called early in the life-cycle (once the plugin has been added). --- #### .[beforeLaunch(options)](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L97-L97) - `options` **LaunchOptions** Puppeteer/Playwright launch options Returns: **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;(LaunchOptions | void)>** Before a new browser instance is created/launched. Can be used to modify the puppeteer/playwright launch options by modifying or returning them. Plugins using this method will be called in sequence to each be able to update the launch options. Example: ```javascript async beforeLaunch (options) { if (this.opts.flashPluginPath) { options.args = options.args || [] options.args.push(`--ppapi-flash-path=${this.opts.flashPluginPath}`) } } ``` --- #### .[afterLaunch(browser, launchContext)](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L125-L125) - `browser` **Browser** The `puppeteer` or `playwright` browser instance. - `launchContext` **LaunchContext** After the browser has launched. Note: Don't assume that there will only be a single browser instance during the lifecycle of a plugin. It's possible that `pupeeteer.launch` will be called multiple times and more than one browser created. In order to make the plugins as stateless as possible don't store a reference to the browser instance in the plugin but rather consider alternatives. E.g. when using `onPageCreated` you can get a browser reference by using `page.browser()`. Alternatively you could expose a class method that takes a browser instance as a parameter to work with: ```es6 const fancyPlugin = require('puppeteer-extra-plugin-fancy')() puppeteer.use(fancyPlugin) const browser = await puppeteer.launch() await fancyPlugin.killBrowser(browser) ``` Example: ```javascript async afterLaunch (browser, opts) { this.debug('browser has been launched', opts.options) } ``` --- #### .[beforeConnect(options)](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L137-L139) - `options` **ConnectOptions** Puppeteer/playwright connect options Returns: **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;(ConnectOptions | void)>** Before connecting to an existing browser instance. Can be used to modify the puppeteer/playwright connect options by modifying or returning them. Plugins using this method will be called in sequence to each be able to update the launch options. --- #### .[afterConnect(browser, launchContext)](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L149-L149) - `browser` **Browser** The `puppeteer` or playwright browser instance. - `launchContext` **LaunchContext** After connecting to an existing browser instance. > Note: Don't assume that there will only be a single browser instance during the lifecycle of a plugin. --- #### .[onBrowser(browser, launchContext)](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L163-L163) - `browser` **Browser** The `puppeteer` or `playwright` browser instance. - `launchContext` **LaunchContext** Called when a browser instance is available. This applies to both `launch` and `connect`. Convenience method created for plugins that need access to a browser instance and don't mind if it has been created through `launch` or `connect`. > Note: Don't assume that there will only be a single browser instance during the lifecycle of a plugin. --- #### .[beforeContext(options, browser)](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L178-L181) - `options` **Playwright.BrowserContextOptions** Playwright browser context options - `browser` **Playwright.Browser** Playwright browser Returns: **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;(Playwright.BrowserContextOptions | void)>** Before a new browser context is created. Note: Currently only triggered by `playwright`, as puppeteer's usage of context is very lackluster. Plugins using this method will be called in sequence to each be able to update the context options. - **See: <https://github.com/microsoft/playwright/blob/master/docs/api.md#browsernewcontextoptions>** --- #### .[onContextCreated(context, options)](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L191-L194) - `context` **Playwright.BrowserContext** Playwright browser context - `options` **Playwright.BrowserContextOptions** Playwright browser context options After a new browser context has been created. Note: `playwright` specific. --- #### .[onPageCreated(page)](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L215-L215) - `page` **(Puppeteer.Page | Playwright.Page)** Called when a page has been created. The event will also fire for popup pages. Example: ```javascript async onPageCreated (page) { let ua = await page.browser().userAgent() if (this.opts.stripHeadless) { ua = ua.replace('HeadlessChrome/', 'Chrome/') } this.debug('new ua', ua) await page.setUserAgent(ua) } ``` - **See: <https://playwright.dev/#version=v1.3.0&path=docs%2Fapi.md&q=event-page>** - **See: <https://pptr.dev/#?product=Puppeteer&version=main&show=api-event-targetcreated>** --- #### .[onPageClose(page)](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L221-L221) - `page` **Page** Called when a page has been closed. --- #### .[onContextClose(context)](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L229-L229) - `context` **Playwright.BrowserContext** Called when a browser context has been closed. Note: `playwright` specific. --- #### .[onDisconnected(browser)](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L240-L240) - `browser` **Browser** The `puppeteer` or `playwright` browser instance. Called when the browser got disconnected. This might happen because of one of the following: - The browser is closed or crashed - The `browser.disconnect` method was called --- ### class: [AutomationExtraPlugin](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L263-L487) **Extends: PluginLifecycleMethods** AutomationExtraPlugin - Meant to be used as a base class and it's methods overridden. Implements all `PluginLifecycleMethods`. Example: ```javascript class Plugin extends AutomationExtraPlugin { static id = 'foobar' constructor(opts = {}) { super(opts) } async beforeLaunch(options) { options.headless = false return options } } ``` --- #### .[env](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L291-L291) Type: **[LauncherEnv](#launcherenv)** Contains info regarding the launcher environment the plugin runs in - **See: LauncherEnv** --- #### .[shim(page)](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L323-L323) - `page` **Page** Returns: **[PageShim](#pageshim)** Unified Page methods for Playwright & Puppeteer --- #### .[defaults](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L352-L354) Type: **PluginOptions** Plugin defaults (optional). If defined will be ([deep-](https://github.com/TehShrike/deepmerge))merged with the (optional) user supplied options (supplied during plugin instantiation). The result of merging defaults with user supplied options can be accessed through `this.opts`. Example: ```javascript get defaults () { return { stripHeadless: true, makeWindows: true, customFn: null } } // Users can overwrite plugin defaults during instantiation: puppeteer.use(require('puppeteer-extra-plugin-foobar')({ makeWindows: false })) ``` - **See: \[[opts]]** --- #### .[requirements](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L380-L382) Type: **PluginRequirements** Plugin requirements (optional). Signal certain plugin requirements to the base class and the user. Currently supported: - `launch` - If the plugin only supports locally created browser instances (no `puppeteer.connect()`), will output a warning to the user. - `headful` - If the plugin doesn't work in `headless: true` mode, will output a warning to the user. - `runLast` - In case the plugin prefers to run after the others. Useful when the plugin needs data from others. Example: ```javascript get requirements () { return new Set(['runLast', 'dataFromPlugins']) } ``` --- #### .[filter](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L399-L401) Type: **(Filter | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))** Plugin filter statements (optional). Filter this plugin from being called depending on the environment. Example: ```javascript get filter() { return { include: ['playwright:chromium', 'puppeteer:chromium'] } } ``` --- #### .[dependencies](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L423-L425) Type: **PluginDependencies** Plugin dependencies (optional). Missing plugins will be required() by automation-extra. Example: ```javascript // Will ensure the 'puppeteer-extra-plugin-user-preferences' plugin is loaded. get dependencies () { return new Set(['user-preferences']) } // Will load `user-preferences` plugin and pass `{ beCool: true }` as opts get dependencies () { return new Map([['user-preferences', { beCool: true }]]) } ``` --- #### .[plugins](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L438-L440) Type: **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;AutomationExtraPluginInstance>** Add additional plugins (optional). Expects an array of AutomationExtraPlugin instances, not classes. This is intended to be used by "meta" plugins that use other plugins behind the scenes. The benefit over using `dependencies` is that this doesn't use the framework for dynamic imports, but requires explicit imports which bundlers like webkit handle much better. Missing plugins listed here will be added at the start of `launch` or `connect` events. --- #### .[opts](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L457-L459) Type: **PluginOptions** Access the plugin options (usually the `defaults` merged with user defined options) To skip the auto-merging of defaults with user supplied opts don't define a `defaults` property and set the `this._opts` Object in your plugin constructor directly. Example: ```javascript get defaults () { return { foo: "bar" } } async onPageCreated (page) { this.debug(this.opts.foo) // => bar } ``` - **See: \[[defaults]]** --- #### .[debug](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L477-L479) Type: **Debugger** Convenience debug logger based on the [debug] module. Will automatically namespace the logging output to the plugin package name. [debug]: https://www.npmjs.com/package/debug ```bash # toggle output using environment variables DEBUG=automation-extra-plugin:<plugin_id> node foo.js # to debug all the things: DEBUG=automation-extra,automation-extra-plugin:* node foo.js ``` Example: ```javascript this.debug('hello world') // will output e.g. 'automation-extra-plugin:anonymize-ua hello world' ``` --- #### .[id](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L285-L285) Plugin id/name (required) Convention: - Package: `automation-extra-plugin-anonymize-ua` - Name: `anonymize-ua` Example: ```javascript static id = 'anonymize-ua'; // or static get id() { return 'anonymize-ua' } ``` --- ### class: [TypeGuards](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L501-L566) TypeGuards: They allow differentiating between different objects and types. Type guards work by discriminating against properties only found in that specific type. This is especially useful when used with TypeScript as it improves type safety. --- #### .[isPage(obj)](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L507-L509) - `obj` **any** The object to test Returns: **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Type guard, will make TypeScript understand which type we're working with. --- #### .[isBrowser(obj)](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L515-L517) - `obj` **any** The object to test Returns: **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Type guard, will make TypeScript understand which type we're working with. --- #### .[isPuppeteerPage(obj)](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L523-L525) - `obj` **any** The object to test Returns: **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Type guard, will make TypeScript understand which type we're working with. --- #### .[isPuppeteerBrowser(obj)](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L531-L533) - `obj` **any** The object to test Returns: **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Type guard, will make TypeScript understand which type we're working with. --- #### .[isPuppeteerBrowserContext(obj)](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L539-L541) - `obj` **any** The object to test Returns: **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Type guard, will make TypeScript understand which type we're working with. --- #### .[isPlaywrightPage(obj)](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L547-L549) - `obj` **any** The object to test Returns: **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Type guard, will make TypeScript understand which type we're working with. --- #### .[isPlaywrightBrowser(obj)](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L555-L557) - `obj` **any** The object to test Returns: **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Type guard, will make TypeScript understand which type we're working with. --- #### .[isPlaywrightBrowserContext(obj)](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L563-L565) - `obj` **any** The object to test Returns: **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Type guard, will make TypeScript understand which type we're working with. --- ### class: [LauncherEnv](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L575-L622) **Extends: TypeGuards** Stores environment specific info, populated by the launcher. This allows sane plugin development in a multi-browser, multi-driver environment. --- #### .[driverName](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L579-L579) The name of the driver currently in use: `"playwright" | "puppeteer"`. --- #### .[browserName](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L587-L587) The name of the browser engine currently in use: `"chromium" | "firefox" | "webkit" | "unknown"`. Note: With puppeteer the browser will only be known once a browser object is available (after launching or connecting), as they support defining the browser during `.launch()`. --- #### .[isPuppeteer](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L599-L601) Check if current driver is puppeteer --- #### .[isPlaywright](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L603-L605) Check if current driver is playwright --- #### .[isChromium](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L607-L609) Check if current browser is chrome or chromium --- #### .[isFirefox](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L611-L613) Check if current browser is firefox --- #### .[isWebkit](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L615-L617) Check if current browser is webkit --- #### .[isBrowserKnown](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L619-L621) Check if current browser is known --- ### class: [PageShim](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L636-L666) Unified Page methods for Playwright & Puppeteer. They support common actions through a single API. --- #### .[addScript(script, arg?)](https://github.com/berstend/puppeteer-extra/blob/9583efba78ac4cfa547f5835592edd4a0f3a5c70/packages/automation-extra-plugin/src/index.ts#L657-L665) - `script` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function))** - `arg` **Serializable?** Adds a script which would be evaluated in one of the following scenarios: Whenever the page is navigated. Whenever the child frame is attached or navigated. In this case, the script is evaluated in the context of the newly attached frame. The script is evaluated after the document was created but before any of its scripts were run. - **See: **Playwright:** `addInitScript` **Puppeteer:** `evaluateOnNewDocument`** --- ## License Copyright © 2018 - 2021, [berstend̡̲̫̹̠̖͚͓̔̄̓̐̄͛̀͘](https://github.com/berstend). Released under the MIT License. <!-- Reference links --> [automation-extra]: https://github.com/berstend/puppeteer-extra/tree/master/packages/automation-extra [playwright-extra]: https://github.com/berstend/puppeteer-extra/tree/master/packages/playwright-extra [puppeteer-extra]: https://github.com/berstend/puppeteer-extra/tree/master/packages/puppeteer-extra