// This file is generated by /doclint/generate_types/index.js import { ChildProcess } from 'child_process'; import { EventEmitter } from 'events'; /** * Can be converted to JSON */ interface Serializable {} interface ConnectionTransport {} /** * This methods attaches Puppeteer to an existing Chromium instance. * @param options */ export function connect(options: ConnectOptions) : Promise; /** * @param options */ export function createBrowserFetcher(options?: CreateBrowserFetcherOptions) : BrowserFetcher; /** * The default flags that Chromium will be launched with. * @param options Set of configurable options to set on the browser. Can have the following fields: */ export function defaultArgs(options?: DefaultArgsOptions) : Array; /** * @returns A path where Puppeteer expects to find bundled Chromium. Chromium might not exist there if the download was skipped with `PUPPETEER_SKIP_CHROMIUM_DOWNLOAD`. */ export function executablePath() : string; /** * You can use `ignoreDefaultArgs` to filter out `--mute-audio` from default arguments: * ```js * const browser = await puppeteer.launch({ * ignoreDefaultArgs: ['--mute-audio'] * }); * ``` * * **NOTE** Puppeteer can also be used to control the Chrome browser, but it works best with the version of Chromium it is bundled with. There is no guarantee it will work with any other version. Use `executablePath` option with extreme caution. * If Google Chrome (rather than Chromium) is preferred, a Chrome Canary or Dev Channel build is suggested. * In puppeteer.launch([options]) above, any mention of Chromium also applies to Chrome. * See `this article` for a description of the differences between Chromium and Chrome. `This article` describes some differences for Linux users. * @param options Set of configurable options to set on the browser. Can have the following fields: * @returns Promise which resolves to browser instance. */ export function launch(options?: LaunchOptions) : Promise; /** * BrowserFetcher can download and manage different versions of Chromium. * BrowserFetcher operates on revision strings that specify a precise version of Chromium, e.g. `"533271"`. Revision strings can be obtained from omahaproxy.appspot.com. * An example of using BrowserFetcher to download a specific version of Chromium and running * Puppeteer against it: * ```js * const browserFetcher = puppeteer.createBrowserFetcher(); * const revisionInfo = await browserFetcher.download('533271'); * const browser = await puppeteer.launch({executablePath: revisionInfo.executablePath}) * ``` * * **NOTE** BrowserFetcher is not designed to work concurrently with other * instances of BrowserFetcher that share the same downloads directory. */ export interface BrowserFetcher { /** * The method initiates a HEAD request to check if the revision is available. * @param revision a revision to check availability. * @returns returns `true` if the revision could be downloaded from the host. */ canDownload(revision: string): Promise; /** * The method initiates a GET request to download the revision from the host. * @param revision a revision to download. * @param progressCallback A function that will be called with two arguments: * @returns Resolves with revision information when the revision is downloaded and extracted */ download(revision: string, progressCallback?: (downloadedBytes : number, totalBytes : number, ...args: any[]) => void): Promise; /** * @returns A list of all revisions available locally on disk. */ localRevisions(): Promise>; /** * @returns One of `mac`, `linux`, `win32` or `win64`. */ platform(): string; /** * @param revision a revision to remove. The method will throw if the revision has not been downloaded. * @returns Resolves when the revision has been removed. */ remove(revision: string): Promise; /** * @param revision a revision to get info for. */ revisionInfo(revision: string): BrowserFetcherRevisionInfo; } /** * A Browser is created when Puppeteer connects to a Chromium instance, either through `puppeteer.launch` or `puppeteer.connect`. * An example of using a Browser to create a Page: * ```js * const puppeteer = require('puppeteer'); * * puppeteer.launch().then(async browser => { * const page = await browser.newPage(); * await page.goto('https://example.com'); * await browser.close(); * }); * ``` * An example of disconnecting from and reconnecting to a Browser: * ```js * const puppeteer = require('puppeteer'); * * puppeteer.launch().then(async browser => { * // Store the endpoint to be able to reconnect to Chromium * const browserWSEndpoint = browser.wsEndpoint(); * // Disconnect puppeteer from Chromium * browser.disconnect(); * * // Use the endpoint to reestablish a connection * const browser2 = await puppeteer.connect({browserWSEndpoint}); * // Close Chromium * await browser2.close(); * }); * ``` */ export interface Browser extends EventEmitter { on(event: 'disconnected', listener: (arg0 : void) => void): this; /** * Emitted when the url of a target changes. * * **NOTE** This includes target changes in incognito browser contexts. */ on(event: 'targetchanged', listener: (arg0 : Target) => void): this; /** * Emitted when a target is created, for example when a new page is opened by `window.open` or `browser.newPage`. * * **NOTE** This includes target creations in incognito browser contexts. */ on(event: 'targetcreated', listener: (arg0 : Target) => void): this; /** * Emitted when a target is destroyed, for example when a page is closed. * * **NOTE** This includes target destructions in incognito browser contexts. */ on(event: 'targetdestroyed', listener: (arg0 : Target) => void): this; once(event: 'disconnected', listener: (arg0 : void) => void): this; /** * Emitted when the url of a target changes. * * **NOTE** This includes target changes in incognito browser contexts. */ once(event: 'targetchanged', listener: (arg0 : Target) => void): this; /** * Emitted when a target is created, for example when a new page is opened by `window.open` or `browser.newPage`. * * **NOTE** This includes target creations in incognito browser contexts. */ once(event: 'targetcreated', listener: (arg0 : Target) => void): this; /** * Emitted when a target is destroyed, for example when a page is closed. * * **NOTE** This includes target destructions in incognito browser contexts. */ once(event: 'targetdestroyed', listener: (arg0 : Target) => void): this; addListener(event: 'disconnected', listener: (arg0 : void) => void): this; /** * Emitted when the url of a target changes. * * **NOTE** This includes target changes in incognito browser contexts. */ addListener(event: 'targetchanged', listener: (arg0 : Target) => void): this; /** * Emitted when a target is created, for example when a new page is opened by `window.open` or `browser.newPage`. * * **NOTE** This includes target creations in incognito browser contexts. */ addListener(event: 'targetcreated', listener: (arg0 : Target) => void): this; /** * Emitted when a target is destroyed, for example when a page is closed. * * **NOTE** This includes target destructions in incognito browser contexts. */ addListener(event: 'targetdestroyed', listener: (arg0 : Target) => void): this; disconnected(): void; /** * Emitted when the url of a target changes. * * **NOTE** This includes target changes in incognito browser contexts. */ targetchanged(): Target; /** * Emitted when a target is created, for example when a new page is opened by `window.open` or `browser.newPage`. * * **NOTE** This includes target creations in incognito browser contexts. */ targetcreated(): Target; /** * Emitted when a target is destroyed, for example when a page is closed. * * **NOTE** This includes target destructions in incognito browser contexts. */ targetdestroyed(): Target; /** * Returns an array of all open browser contexts. In a newly created browser, this will return * a single instance of BrowserContext. */ browserContexts(): Array; /** * Closes Chromium and all of its pages (if any were opened). The Browser object itself is considered to be disposed and cannot be used anymore. */ close(): Promise; /** * Creates a new incognito browser context. This won't share cookies/cache with other browser contexts. * ```js * const browser = await puppeteer.launch(); * // Create a new incognito browser context. * const context = await browser.createIncognitoBrowserContext(); * // Create a new page in a pristine context. * const page = await context.newPage(); * // Do stuff * await page.goto('https://example.com'); * ``` */ createIncognitoBrowserContext(): Promise; /** * Returns the default browser context. The default browser context can not be closed. */ defaultBrowserContext(): BrowserContext; /** * browser.disconnect() * Disconnects Puppeteer from the browser, but leaves the Chromium process running. After calling `disconnect`, the Browser object is considered disposed and cannot be used anymore. */ disconnect(): void; /** * Promise which resolves to a new Page object. The Page is created in a default browser context. */ newPage(): Promise; /** * An array of all pages inside the Browser. In case of multiple browser contexts, * the method will return an array with all the pages in all browser contexts. * @returns Promise which resolves to an array of all open pages. Non visible pages, such as `"background_page"`, will not be listed here. You can find them using target.page(). */ pages(): Promise>; /** * @returns Spawned browser process. Returns `null` if the browser instance was created with `puppeteer.connect` method. */ process(): null|ChildProcess; /** * A target associated with the browser. */ target(): Target; /** * An array of all active targets inside the Browser. In case of multiple browser contexts, * the method will return an array with all the targets in all browser contexts. */ targets(): Array; /** * **NOTE** Pages can override browser user agent with page.setUserAgent * @returns Promise which resolves to the browser's original user agent. */ userAgent(): Promise; /** * **NOTE** the format of browser.version() might change with future releases of Chromium. * @returns For headless Chromium, this is similar to `HeadlessChrome/61.0.3153.0`. For non-headless, this is similar to `Chrome/61.0.3153.0`. */ version(): Promise; /** * This searches for a target in all browser contexts. * An example of finding a target for a page opened via `window.open`: * ```js * await page.evaluate(() => window.open('https://www.example.com/')); * const newWindowTarget = await browser.waitForTarget(target => target.url() === 'https://www.example.com/'); * ``` * @param predicate A function to be run for every target * @param options * @returns Promise which resolves to the first target found that matches the `predicate` function. */ waitForTarget(predicate: (arg0 : Target, ...args: any[]) => boolean, options?: BrowserWaitForTargetOptions): Promise; /** * Browser websocket endpoint which can be used as an argument to * puppeteer.connect. The format is `ws://${host}:${port}/devtools/browser/` * You can find the `webSocketDebuggerUrl` from `http://${host}:${port}/json/version`. Learn more about the devtools protocol and the browser endpoint. * @returns Browser websocket url. */ wsEndpoint(): string; } /** * BrowserContexts provide a way to operate multiple independent browser sessions. When a browser is launched, it has * a single BrowserContext used by default. The method `browser.newPage()` creates a page in the default browser context. * If a page opens another page, e.g. with a `window.open` call, the popup will belong to the parent page's browser * context. * Puppeteer allows creation of "incognito" browser contexts with `browser.createIncognitoBrowserContext()` method. * "Incognito" browser contexts don't write any browsing data to disk. * ```js * // Create a new incognito browser context * const context = await browser.createIncognitoBrowserContext(); * // Create a new page inside context. * const page = await context.newPage(); * // ... do stuff with page ... * await page.goto('https://example.com'); * // Dispose context once it's no longer needed. * await context.close(); * ``` */ export interface BrowserContext extends EventEmitter { /** * Emitted when the url of a target inside the browser context changes. */ on(event: 'targetchanged', listener: (arg0 : Target) => void): this; /** * Emitted when a new target is created inside the browser context, for example when a new page is opened by `window.open` or `browserContext.newPage`. */ on(event: 'targetcreated', listener: (arg0 : Target) => void): this; /** * Emitted when a target inside the browser context is destroyed, for example when a page is closed. */ on(event: 'targetdestroyed', listener: (arg0 : Target) => void): this; /** * Emitted when the url of a target inside the browser context changes. */ once(event: 'targetchanged', listener: (arg0 : Target) => void): this; /** * Emitted when a new target is created inside the browser context, for example when a new page is opened by `window.open` or `browserContext.newPage`. */ once(event: 'targetcreated', listener: (arg0 : Target) => void): this; /** * Emitted when a target inside the browser context is destroyed, for example when a page is closed. */ once(event: 'targetdestroyed', listener: (arg0 : Target) => void): this; /** * Emitted when the url of a target inside the browser context changes. */ addListener(event: 'targetchanged', listener: (arg0 : Target) => void): this; /** * Emitted when a new target is created inside the browser context, for example when a new page is opened by `window.open` or `browserContext.newPage`. */ addListener(event: 'targetcreated', listener: (arg0 : Target) => void): this; /** * Emitted when a target inside the browser context is destroyed, for example when a page is closed. */ addListener(event: 'targetdestroyed', listener: (arg0 : Target) => void): this; /** * Emitted when the url of a target inside the browser context changes. */ targetchanged(): Target; /** * Emitted when a new target is created inside the browser context, for example when a new page is opened by `window.open` or `browserContext.newPage`. */ targetcreated(): Target; /** * Emitted when a target inside the browser context is destroyed, for example when a page is closed. */ targetdestroyed(): Target; /** * The browser this browser context belongs to. */ browser(): Browser; /** * Clears all permission overrides for the browser context. * ```js * const context = browser.defaultBrowserContext(); * context.overridePermissions('https://example.com', ['clipboard-read']); * // do stuff .. * context.clearPermissionOverrides(); * ``` */ clearPermissionOverrides(): Promise; /** * Closes the browser context. All the targets that belong to the browser context * will be closed. * * **NOTE** only incognito browser contexts can be closed. */ close(): Promise; /** * Returns whether BrowserContext is incognito. * The default browser context is the only non-incognito browser context. * * **NOTE** the default browser context cannot be closed. */ isIncognito(): boolean; /** * Creates a new page in the browser context. */ newPage(): Promise; /** * ```js * const context = browser.defaultBrowserContext(); * await context.overridePermissions('https://html5demos.com', ['geolocation']); * ``` * @param origin The origin to grant permissions to, e.g. "https://example.com". * @param permissions An array of permissions to grant. All permissions that are not listed here will be automatically denied. Permissions can be one of the following values: */ overridePermissions(origin: string, permissions: Array): Promise; /** * An array of all pages inside the browser context. * @returns Promise which resolves to an array of all open pages. Non visible pages, such as `"background_page"`, will not be listed here. You can find them using target.page(). */ pages(): Promise>; /** * An array of all active targets inside the browser context. */ targets(): Array; /** * This searches for a target in this specific browser context. * An example of finding a target for a page opened via `window.open`: * ```js * await page.evaluate(() => window.open('https://www.example.com/')); * const newWindowTarget = await browserContext.waitForTarget(target => target.url() === 'https://www.example.com/'); * ``` * @param predicate A function to be run for every target * @param options * @returns Promise which resolves to the first target found that matches the `predicate` function. */ waitForTarget(predicate: (arg0 : Target, ...args: any[]) => boolean, options?: BrowserContextWaitForTargetOptions): Promise; } /** * Page provides methods to interact with a single tab or extension background page in Chromium. One Browser instance might have multiple Page instances. * This example creates a page, navigates it to a URL, and then saves a screenshot: * ```js * const puppeteer = require('puppeteer'); * * puppeteer.launch().then(async browser => { * const page = await browser.newPage(); * await page.goto('https://example.com'); * await page.screenshot({path: 'screenshot.png'}); * await browser.close(); * }); * ``` * The Page class emits various events (described below) which can be handled using any of Node's native `EventEmitter` methods, such as `on`, `once` or `removeListener`. * This example logs a message for a single page `load` event: * ```js * page.once('load', () => console.log('Page loaded!')); * ``` * To unsubscribe from events use the `removeListener` method: * ```js * function logRequest(interceptedRequest) { * console.log('A request was made:', interceptedRequest.url()); * } * page.on('request', logRequest); * // Sometime later... * page.removeListener('request', logRequest); * ``` */ export interface Page extends EventEmitter { /** * event: 'close' * Emitted when the page closes. */ on(event: 'close', listener: (arg0 : void) => void): this; /** * Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. Also emitted if the page throws an error or a warning. * The arguments passed into `console.log` appear as arguments on the event handler. * An example of handling `console` event: * ```js * page.on('console', msg => { * for (let i = 0; i < msg.args().length; ++i) * console.log(`${i}: ${msg.args()[i]}`); * }); * page.evaluate(() => console.log('hello', 5, {foo: 'bar'})); * ``` */ on(event: 'console', listener: (arg0 : ConsoleMessage) => void): this; /** * Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Puppeteer can respond to the dialog via Dialog's accept or dismiss methods. */ on(event: 'dialog', listener: (arg0 : Dialog) => void): this; /** * event: 'domcontentloaded' * Emitted when the JavaScript `DOMContentLoaded` event is dispatched. */ on(event: 'domcontentloaded', listener: (arg0 : void) => void): this; /** * Emitted when the page crashes. * * **NOTE** `error` event has a special meaning in Node, see error events for details. */ on(event: 'error', listener: (arg0 : Error) => void): this; /** * Emitted when a frame is attached. */ on(event: 'frameattached', listener: (arg0 : Frame) => void): this; /** * Emitted when a frame is detached. */ on(event: 'framedetached', listener: (arg0 : Frame) => void): this; /** * Emitted when a frame is navigated to a new url. */ on(event: 'framenavigated', listener: (arg0 : Frame) => void): this; /** * event: 'load' * Emitted when the JavaScript `load` event is dispatched. */ on(event: 'load', listener: (arg0 : void) => void): this; /** * Emitted when the JavaScript code makes a call to `console.timeStamp`. For the list * of metrics see `page.metrics`. */ on(event: 'metrics', listener: (arg0 : PageMetricsPayload) => void): this; /** * Emitted when an uncaught exception happens within the page. */ on(event: 'pageerror', listener: (arg0 : Error) => void): this; /** * Emitted when the page opens a new tab or window. * ```js * const [popup] = await Promise.all([ * new Promise(resolve => page.once('popup', resolve)), * page.click('a[target=_blank]'), * ]); * ``` * ```js * const [popup] = await Promise.all([ * new Promise(resolve => page.once('popup', resolve)), * page.evaluate(() => window.open('https://example.com')), * ]); * ``` */ on(event: 'popup', listener: (arg0 : Page) => void): this; /** * Emitted when a page issues a request. The request object is read-only. * In order to intercept and mutate requests, see `page.setRequestInterception`. */ on(event: 'request', listener: (arg0 : Request) => void): this; /** * Emitted when a request fails, for example by timing out. */ on(event: 'requestfailed', listener: (arg0 : Request) => void): this; /** * Emitted when a request finishes successfully. */ on(event: 'requestfinished', listener: (arg0 : Request) => void): this; /** * Emitted when a response is received. */ on(event: 'response', listener: (arg0 : Response) => void): this; /** * Emitted when a dedicated WebWorker is spawned by the page. */ on(event: 'workercreated', listener: (arg0 : Worker) => void): this; /** * Emitted when a dedicated WebWorker is terminated. */ on(event: 'workerdestroyed', listener: (arg0 : Worker) => void): this; /** * event: 'close' * Emitted when the page closes. */ once(event: 'close', listener: (arg0 : void) => void): this; /** * Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. Also emitted if the page throws an error or a warning. * The arguments passed into `console.log` appear as arguments on the event handler. * An example of handling `console` event: * ```js * page.on('console', msg => { * for (let i = 0; i < msg.args().length; ++i) * console.log(`${i}: ${msg.args()[i]}`); * }); * page.evaluate(() => console.log('hello', 5, {foo: 'bar'})); * ``` */ once(event: 'console', listener: (arg0 : ConsoleMessage) => void): this; /** * Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Puppeteer can respond to the dialog via Dialog's accept or dismiss methods. */ once(event: 'dialog', listener: (arg0 : Dialog) => void): this; /** * event: 'domcontentloaded' * Emitted when the JavaScript `DOMContentLoaded` event is dispatched. */ once(event: 'domcontentloaded', listener: (arg0 : void) => void): this; /** * Emitted when the page crashes. * * **NOTE** `error` event has a special meaning in Node, see error events for details. */ once(event: 'error', listener: (arg0 : Error) => void): this; /** * Emitted when a frame is attached. */ once(event: 'frameattached', listener: (arg0 : Frame) => void): this; /** * Emitted when a frame is detached. */ once(event: 'framedetached', listener: (arg0 : Frame) => void): this; /** * Emitted when a frame is navigated to a new url. */ once(event: 'framenavigated', listener: (arg0 : Frame) => void): this; /** * event: 'load' * Emitted when the JavaScript `load` event is dispatched. */ once(event: 'load', listener: (arg0 : void) => void): this; /** * Emitted when the JavaScript code makes a call to `console.timeStamp`. For the list * of metrics see `page.metrics`. */ once(event: 'metrics', listener: (arg0 : PageMetricsPayload) => void): this; /** * Emitted when an uncaught exception happens within the page. */ once(event: 'pageerror', listener: (arg0 : Error) => void): this; /** * Emitted when the page opens a new tab or window. * ```js * const [popup] = await Promise.all([ * new Promise(resolve => page.once('popup', resolve)), * page.click('a[target=_blank]'), * ]); * ``` * ```js * const [popup] = await Promise.all([ * new Promise(resolve => page.once('popup', resolve)), * page.evaluate(() => window.open('https://example.com')), * ]); * ``` */ once(event: 'popup', listener: (arg0 : Page) => void): this; /** * Emitted when a page issues a request. The request object is read-only. * In order to intercept and mutate requests, see `page.setRequestInterception`. */ once(event: 'request', listener: (arg0 : Request) => void): this; /** * Emitted when a request fails, for example by timing out. */ once(event: 'requestfailed', listener: (arg0 : Request) => void): this; /** * Emitted when a request finishes successfully. */ once(event: 'requestfinished', listener: (arg0 : Request) => void): this; /** * Emitted when a response is received. */ once(event: 'response', listener: (arg0 : Response) => void): this; /** * Emitted when a dedicated WebWorker is spawned by the page. */ once(event: 'workercreated', listener: (arg0 : Worker) => void): this; /** * Emitted when a dedicated WebWorker is terminated. */ once(event: 'workerdestroyed', listener: (arg0 : Worker) => void): this; /** * event: 'close' * Emitted when the page closes. */ addListener(event: 'close', listener: (arg0 : void) => void): this; /** * Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. Also emitted if the page throws an error or a warning. * The arguments passed into `console.log` appear as arguments on the event handler. * An example of handling `console` event: * ```js * page.on('console', msg => { * for (let i = 0; i < msg.args().length; ++i) * console.log(`${i}: ${msg.args()[i]}`); * }); * page.evaluate(() => console.log('hello', 5, {foo: 'bar'})); * ``` */ addListener(event: 'console', listener: (arg0 : ConsoleMessage) => void): this; /** * Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Puppeteer can respond to the dialog via Dialog's accept or dismiss methods. */ addListener(event: 'dialog', listener: (arg0 : Dialog) => void): this; /** * event: 'domcontentloaded' * Emitted when the JavaScript `DOMContentLoaded` event is dispatched. */ addListener(event: 'domcontentloaded', listener: (arg0 : void) => void): this; /** * Emitted when the page crashes. * * **NOTE** `error` event has a special meaning in Node, see error events for details. */ addListener(event: 'error', listener: (arg0 : Error) => void): this; /** * Emitted when a frame is attached. */ addListener(event: 'frameattached', listener: (arg0 : Frame) => void): this; /** * Emitted when a frame is detached. */ addListener(event: 'framedetached', listener: (arg0 : Frame) => void): this; /** * Emitted when a frame is navigated to a new url. */ addListener(event: 'framenavigated', listener: (arg0 : Frame) => void): this; /** * event: 'load' * Emitted when the JavaScript `load` event is dispatched. */ addListener(event: 'load', listener: (arg0 : void) => void): this; /** * Emitted when the JavaScript code makes a call to `console.timeStamp`. For the list * of metrics see `page.metrics`. */ addListener(event: 'metrics', listener: (arg0 : PageMetricsPayload) => void): this; /** * Emitted when an uncaught exception happens within the page. */ addListener(event: 'pageerror', listener: (arg0 : Error) => void): this; /** * Emitted when the page opens a new tab or window. * ```js * const [popup] = await Promise.all([ * new Promise(resolve => page.once('popup', resolve)), * page.click('a[target=_blank]'), * ]); * ``` * ```js * const [popup] = await Promise.all([ * new Promise(resolve => page.once('popup', resolve)), * page.evaluate(() => window.open('https://example.com')), * ]); * ``` */ addListener(event: 'popup', listener: (arg0 : Page) => void): this; /** * Emitted when a page issues a request. The request object is read-only. * In order to intercept and mutate requests, see `page.setRequestInterception`. */ addListener(event: 'request', listener: (arg0 : Request) => void): this; /** * Emitted when a request fails, for example by timing out. */ addListener(event: 'requestfailed', listener: (arg0 : Request) => void): this; /** * Emitted when a request finishes successfully. */ addListener(event: 'requestfinished', listener: (arg0 : Request) => void): this; /** * Emitted when a response is received. */ addListener(event: 'response', listener: (arg0 : Response) => void): this; /** * Emitted when a dedicated WebWorker is spawned by the page. */ addListener(event: 'workercreated', listener: (arg0 : Worker) => void): this; /** * Emitted when a dedicated WebWorker is terminated. */ addListener(event: 'workerdestroyed', listener: (arg0 : Worker) => void): this; /** * event: 'close' * Emitted when the page closes. */ close(): void; /** * Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. Also emitted if the page throws an error or a warning. * The arguments passed into `console.log` appear as arguments on the event handler. * An example of handling `console` event: * ```js * page.on('console', msg => { * for (let i = 0; i < msg.args().length; ++i) * console.log(`${i}: ${msg.args()[i]}`); * }); * page.evaluate(() => console.log('hello', 5, {foo: 'bar'})); * ``` */ console(): ConsoleMessage; /** * Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Puppeteer can respond to the dialog via Dialog's accept or dismiss methods. */ dialog(): Dialog; /** * event: 'domcontentloaded' * Emitted when the JavaScript `DOMContentLoaded` event is dispatched. */ domcontentloaded(): void; /** * Emitted when the page crashes. * * **NOTE** `error` event has a special meaning in Node, see error events for details. */ error(): Error; /** * Emitted when a frame is attached. */ frameattached(): Frame; /** * Emitted when a frame is detached. */ framedetached(): Frame; /** * Emitted when a frame is navigated to a new url. */ framenavigated(): Frame; /** * event: 'load' * Emitted when the JavaScript `load` event is dispatched. */ load(): void; /** * Emitted when the JavaScript code makes a call to `console.timeStamp`. For the list * of metrics see `page.metrics`. */ metrics(): PageMetrics; /** * Emitted when an uncaught exception happens within the page. */ pageerror(): Error; /** * Emitted when the page opens a new tab or window. * ```js * const [popup] = await Promise.all([ * new Promise(resolve => page.once('popup', resolve)), * page.click('a[target=_blank]'), * ]); * ``` * ```js * const [popup] = await Promise.all([ * new Promise(resolve => page.once('popup', resolve)), * page.evaluate(() => window.open('https://example.com')), * ]); * ``` */ popup(): Page; /** * Emitted when a page issues a request. The request object is read-only. * In order to intercept and mutate requests, see `page.setRequestInterception`. */ request(): Request; /** * Emitted when a request fails, for example by timing out. */ requestfailed(): Request; /** * Emitted when a request finishes successfully. */ requestfinished(): Request; /** * Emitted when a response is received. */ response(): Response; /** * Emitted when a dedicated WebWorker is spawned by the page. */ workercreated(): Worker; /** * Emitted when a dedicated WebWorker is terminated. */ workerdestroyed(): Worker; /** * The method runs `document.querySelector` within the page. If no element matches the selector, the return value resolves to `null`. * Shortcut for page.mainFrame().$(selector). * @param selector A selector to query page for */ $(selector: string): Promise; /** * The method runs `document.querySelectorAll` within the page. If no elements match the selector, the return value resolves to `[]`. * Shortcut for page.mainFrame().$$(selector). * @param selector A selector to query page for */ $$(selector: string): Promise>; /** * This method runs `Array.from(document.querySelectorAll(selector))` within the page and passes it as the first argument to `pageFunction`. * If `pageFunction` returns a Promise, then `page.$$eval` would wait for the promise to resolve and return its value. * Examples: * ```js * const divsCounts = await page.$$eval('div', divs => divs.length); * ``` * @param selector A selector to query page for * @param pageFunction Function to be evaluated in browser context * @param args Arguments to pass to `pageFunction` * @returns Promise which resolves to the return value of `pageFunction` */ $$eval(selector: string, pageFunction: (arg0 : Array, ...args: any[]) => void, ...args: Array): Promise; /** * This method runs `document.querySelector` within the page and passes it as the first argument to `pageFunction`. If there's no element matching `selector`, the method throws an error. * If `pageFunction` returns a Promise, then `page.$eval` would wait for the promise to resolve and return its value. * Examples: * ```js * const searchValue = await page.$eval('#search', el => el.value); * const preloadHref = await page.$eval('link[rel=preload]', el => el.href); * const html = await page.$eval('.main-container', e => e.outerHTML); * ``` * Shortcut for page.mainFrame().$eval(selector, pageFunction). * @param selector A selector to query page for * @param pageFunction Function to be evaluated in browser context * @param args Arguments to pass to `pageFunction` * @returns Promise which resolves to the return value of `pageFunction` */ $eval(selector: string, pageFunction: (arg0 : Element, ...args: any[]) => void, ...args: Array): Promise; /** * The method evaluates the XPath expression. * Shortcut for page.mainFrame().$x(expression) * @param expression Expression to evaluate. */ $x(expression: string): Promise>; accessibility: Accessibility; /** * Adds a `