rebrowser-playwright-core
Version:
A drop-in replacement for playwright-core patched with rebrowser-patches. It allows to pass modern automation detection tests.
1,028 lines (1,015 loc) • 931 kB
TypeScript
// This file is generated by /utils/generate_types/index.js
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ChildProcess } from 'child_process';
import { EventEmitter } from 'events';
import { Readable } from 'stream';
import { ReadStream } from 'fs';
import { Protocol } from './protocol';
import { Serializable, EvaluationArgument, PageFunction, PageFunctionOn, SmartHandle, ElementHandleForTag, BindingSource } from './structs';
type PageWaitForSelectorOptionsNotHidden = PageWaitForSelectorOptions & {
state?: 'visible'|'attached';
};
type ElementHandleWaitForSelectorOptionsNotHidden = ElementHandleWaitForSelectorOptions & {
state?: 'visible'|'attached';
};
/**
* Page provides methods to interact with a single tab in a [Browser](https://playwright.dev/docs/api/class-browser),
* or an [extension background page](https://developer.chrome.com/extensions/background_pages) in Chromium. One
* [Browser](https://playwright.dev/docs/api/class-browser) instance might have multiple
* [Page](https://playwright.dev/docs/api/class-page) instances.
*
* This example creates a page, navigates it to a URL, and then saves a screenshot:
*
* ```js
* const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
*
* (async () => {
* const browser = await webkit.launch();
* const context = await browser.newContext();
* const page = await context.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`](https://nodejs.org/api/events.html#events_class_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 {
/**
* Returns the value of the
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-evaluate-option-expression) invocation.
*
* If the function passed to the
* [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate) returns a [Promise],
* then [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate) would wait for
* the promise to resolve and return its value.
*
* If the function passed to the
* [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate) returns a
* non-[Serializable] value, then
* [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate) resolves to
* `undefined`. Playwright also supports transferring some additional values that are not serializable by `JSON`:
* `-0`, `NaN`, `Infinity`, `-Infinity`.
*
* **Usage**
*
* Passing argument to [`pageFunction`](https://playwright.dev/docs/api/class-page#page-evaluate-option-expression):
*
* ```js
* const result = await page.evaluate(([x, y]) => {
* return Promise.resolve(x * y);
* }, [7, 8]);
* console.log(result); // prints "56"
* ```
*
* A string can also be passed in instead of a function:
*
* ```js
* console.log(await page.evaluate('1 + 2')); // prints "3"
* const x = 10;
* console.log(await page.evaluate(`1 + ${x}`)); // prints "11"
* ```
*
* [ElementHandle](https://playwright.dev/docs/api/class-elementhandle) instances can be passed as an argument to the
* [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate):
*
* ```js
* const bodyHandle = await page.evaluate('document.body');
* const html = await page.evaluate<string, HTMLElement>(([body, suffix]) =>
* body.innerHTML + suffix, [bodyHandle, 'hello']
* );
* await bodyHandle.dispose();
* ```
*
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-evaluate-option-expression).
*/
evaluate<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg): Promise<R>;
/**
* Returns the value of the
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-evaluate-option-expression) invocation.
*
* If the function passed to the
* [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate) returns a [Promise],
* then [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate) would wait for
* the promise to resolve and return its value.
*
* If the function passed to the
* [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate) returns a
* non-[Serializable] value, then
* [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate) resolves to
* `undefined`. Playwright also supports transferring some additional values that are not serializable by `JSON`:
* `-0`, `NaN`, `Infinity`, `-Infinity`.
*
* **Usage**
*
* Passing argument to [`pageFunction`](https://playwright.dev/docs/api/class-page#page-evaluate-option-expression):
*
* ```js
* const result = await page.evaluate(([x, y]) => {
* return Promise.resolve(x * y);
* }, [7, 8]);
* console.log(result); // prints "56"
* ```
*
* A string can also be passed in instead of a function:
*
* ```js
* console.log(await page.evaluate('1 + 2')); // prints "3"
* const x = 10;
* console.log(await page.evaluate(`1 + ${x}`)); // prints "11"
* ```
*
* [ElementHandle](https://playwright.dev/docs/api/class-elementhandle) instances can be passed as an argument to the
* [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate):
*
* ```js
* const bodyHandle = await page.evaluate('document.body');
* const html = await page.evaluate<string, HTMLElement>(([body, suffix]) =>
* body.innerHTML + suffix, [bodyHandle, 'hello']
* );
* await bodyHandle.dispose();
* ```
*
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-evaluate-option-expression).
*/
evaluate<R>(pageFunction: PageFunction<void, R>, arg?: any): Promise<R>;
/**
* Returns the value of the
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-evaluate-handle-option-expression) invocation as a
* [JSHandle](https://playwright.dev/docs/api/class-jshandle).
*
* The only difference between
* [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate) and
* [page.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate-handle) is that
* [page.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate-handle) returns
* [JSHandle](https://playwright.dev/docs/api/class-jshandle).
*
* If the function passed to the
* [page.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate-handle) returns
* a [Promise], then
* [page.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate-handle) would
* wait for the promise to resolve and return its value.
*
* **Usage**
*
* ```js
* // Handle for the window object.
* const aWindowHandle = await page.evaluateHandle(() => Promise.resolve(window));
* ```
*
* A string can also be passed in instead of a function:
*
* ```js
* const aHandle = await page.evaluateHandle('document'); // Handle for the 'document'
* ```
*
* [JSHandle](https://playwright.dev/docs/api/class-jshandle) instances can be passed as an argument to the
* [page.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate-handle):
*
* ```js
* const aHandle = await page.evaluateHandle(() => document.body);
* const resultHandle = await page.evaluateHandle(body => body.innerHTML, aHandle);
* console.log(await resultHandle.jsonValue());
* await resultHandle.dispose();
* ```
*
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-evaluate-handle-option-expression).
*/
evaluateHandle<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg): Promise<SmartHandle<R>>;
/**
* Returns the value of the
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-evaluate-handle-option-expression) invocation as a
* [JSHandle](https://playwright.dev/docs/api/class-jshandle).
*
* The only difference between
* [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate) and
* [page.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate-handle) is that
* [page.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate-handle) returns
* [JSHandle](https://playwright.dev/docs/api/class-jshandle).
*
* If the function passed to the
* [page.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate-handle) returns
* a [Promise], then
* [page.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate-handle) would
* wait for the promise to resolve and return its value.
*
* **Usage**
*
* ```js
* // Handle for the window object.
* const aWindowHandle = await page.evaluateHandle(() => Promise.resolve(window));
* ```
*
* A string can also be passed in instead of a function:
*
* ```js
* const aHandle = await page.evaluateHandle('document'); // Handle for the 'document'
* ```
*
* [JSHandle](https://playwright.dev/docs/api/class-jshandle) instances can be passed as an argument to the
* [page.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate-handle):
*
* ```js
* const aHandle = await page.evaluateHandle(() => document.body);
* const resultHandle = await page.evaluateHandle(body => body.innerHTML, aHandle);
* console.log(await resultHandle.jsonValue());
* await resultHandle.dispose();
* ```
*
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-evaluate-handle-option-expression).
*/
evaluateHandle<R>(pageFunction: PageFunction<void, R>, arg?: any): Promise<SmartHandle<R>>;
/**
* 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. This is useful to
* amend the JavaScript environment, e.g. to seed `Math.random`.
*
* **Usage**
*
* An example of overriding `Math.random` before the page loads:
*
* ```js
* // preload.js
* Math.random = () => 42;
* ```
*
* ```js
* // In your playwright script, assuming the preload.js file is in same directory
* await page.addInitScript({ path: './preload.js' });
* ```
*
* ```js
* await page.addInitScript(mock => {
* window.mock = mock;
* }, mock);
* ```
*
* **NOTE** The order of evaluation of multiple scripts installed via
* [browserContext.addInitScript(script[, arg])](https://playwright.dev/docs/api/class-browsercontext#browser-context-add-init-script)
* and [page.addInitScript(script[, arg])](https://playwright.dev/docs/api/class-page#page-add-init-script) is not
* defined.
*
* @param script Script to be evaluated in the page.
* @param arg Optional argument to pass to
* [`script`](https://playwright.dev/docs/api/class-page#page-add-init-script-option-script) (only supported when
* passing a function).
*/
addInitScript<Arg>(script: PageFunction<Arg, any> | { path?: string, content?: string }, arg?: Arg): Promise<void>;
/**
* **NOTE** Use locator-based [page.locator(selector[, options])](https://playwright.dev/docs/api/class-page#page-locator)
* instead. Read more about [locators](https://playwright.dev/docs/locators).
*
* The method finds an element matching the specified selector within the page. If no elements match the selector, the
* return value resolves to `null`. To wait for an element on the page, use
* [locator.waitFor([options])](https://playwright.dev/docs/api/class-locator#locator-wait-for).
* @param selector A selector to query for.
* @param options
*/
$<K extends keyof HTMLElementTagNameMap>(selector: K, options?: { strict: boolean }): Promise<ElementHandleForTag<K> | null>;
/**
* **NOTE** Use locator-based [page.locator(selector[, options])](https://playwright.dev/docs/api/class-page#page-locator)
* instead. Read more about [locators](https://playwright.dev/docs/locators).
*
* The method finds an element matching the specified selector within the page. If no elements match the selector, the
* return value resolves to `null`. To wait for an element on the page, use
* [locator.waitFor([options])](https://playwright.dev/docs/api/class-locator#locator-wait-for).
* @param selector A selector to query for.
* @param options
*/
$(selector: string, options?: { strict: boolean }): Promise<ElementHandle<SVGElement | HTMLElement> | null>;
/**
* **NOTE** Use locator-based [page.locator(selector[, options])](https://playwright.dev/docs/api/class-page#page-locator)
* instead. Read more about [locators](https://playwright.dev/docs/locators).
*
* The method finds all elements matching the specified selector within the page. If no elements match the selector,
* the return value resolves to `[]`.
* @param selector A selector to query for.
*/
$$<K extends keyof HTMLElementTagNameMap>(selector: K): Promise<ElementHandleForTag<K>[]>;
/**
* **NOTE** Use locator-based [page.locator(selector[, options])](https://playwright.dev/docs/api/class-page#page-locator)
* instead. Read more about [locators](https://playwright.dev/docs/locators).
*
* The method finds all elements matching the specified selector within the page. If no elements match the selector,
* the return value resolves to `[]`.
* @param selector A selector to query for.
*/
$$(selector: string): Promise<ElementHandle<SVGElement | HTMLElement>[]>;
/**
* **NOTE** This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests.
* Use
* [locator.evaluate(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods or web-first assertions instead.
*
* The method finds an element matching the specified selector within the page and passes it as a first argument to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression). If no
* elements match the selector, the method throws an error. Returns the value of
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression).
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression) returns a
* [Promise], then
* [page.$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-eval-on-selector)
* would wait for the promise to resolve and return its value.
*
* **Usage**
*
* ```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, suffix) => e.outerHTML + suffix, 'hello');
* // In TypeScript, this example requires an explicit type annotation (HTMLLinkElement) on el:
* const preloadHrefTS = await page.$eval('link[rel=preload]', (el: HTMLLinkElement) => el.href);
* ```
*
* @param selector A selector to query for.
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression).
* @param options
*/
$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests.
* Use
* [locator.evaluate(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods or web-first assertions instead.
*
* The method finds an element matching the specified selector within the page and passes it as a first argument to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression). If no
* elements match the selector, the method throws an error. Returns the value of
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression).
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression) returns a
* [Promise], then
* [page.$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-eval-on-selector)
* would wait for the promise to resolve and return its value.
*
* **Usage**
*
* ```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, suffix) => e.outerHTML + suffix, 'hello');
* // In TypeScript, this example requires an explicit type annotation (HTMLLinkElement) on el:
* const preloadHrefTS = await page.$eval('link[rel=preload]', (el: HTMLLinkElement) => el.href);
* ```
*
* @param selector A selector to query for.
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression).
* @param options
*/
$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests.
* Use
* [locator.evaluate(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods or web-first assertions instead.
*
* The method finds an element matching the specified selector within the page and passes it as a first argument to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression). If no
* elements match the selector, the method throws an error. Returns the value of
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression).
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression) returns a
* [Promise], then
* [page.$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-eval-on-selector)
* would wait for the promise to resolve and return its value.
*
* **Usage**
*
* ```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, suffix) => e.outerHTML + suffix, 'hello');
* // In TypeScript, this example requires an explicit type annotation (HTMLLinkElement) on el:
* const preloadHrefTS = await page.$eval('link[rel=preload]', (el: HTMLLinkElement) => el.href);
* ```
*
* @param selector A selector to query for.
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression).
* @param options
*/
$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any): Promise<R>;
/**
* **NOTE** This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests.
* Use
* [locator.evaluate(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-locator#locator-evaluate),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods or web-first assertions instead.
*
* The method finds an element matching the specified selector within the page and passes it as a first argument to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression). If no
* elements match the selector, the method throws an error. Returns the value of
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression).
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression) returns a
* [Promise], then
* [page.$eval(selector, pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-eval-on-selector)
* would wait for the promise to resolve and return its value.
*
* **Usage**
*
* ```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, suffix) => e.outerHTML + suffix, 'hello');
* // In TypeScript, this example requires an explicit type annotation (HTMLLinkElement) on el:
* const preloadHrefTS = await page.$eval('link[rel=preload]', (el: HTMLLinkElement) => el.href);
* ```
*
* @param selector A selector to query for.
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-option-expression).
* @param options
*/
$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any): Promise<R>;
/**
* **NOTE** In most cases,
* [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
* The method finds all elements matching the specified selector within the page and passes an array of matched
* elements as a first argument to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression). Returns
* the result of
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression)
* invocation.
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression) returns
* a [Promise], then
* [page.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
*
* ```js
* const divCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 10);
* ```
*
* @param selector A selector to query for.
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression).
*/
$$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** In most cases,
* [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
* The method finds all elements matching the specified selector within the page and passes an array of matched
* elements as a first argument to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression). Returns
* the result of
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression)
* invocation.
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression) returns
* a [Promise], then
* [page.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
*
* ```js
* const divCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 10);
* ```
*
* @param selector A selector to query for.
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression).
*/
$$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg): Promise<R>;
/**
* **NOTE** In most cases,
* [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
* The method finds all elements matching the specified selector within the page and passes an array of matched
* elements as a first argument to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression). Returns
* the result of
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression)
* invocation.
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression) returns
* a [Promise], then
* [page.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
*
* ```js
* const divCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 10);
* ```
*
* @param selector A selector to query for.
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression).
*/
$$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any): Promise<R>;
/**
* **NOTE** In most cases,
* [locator.evaluateAll(pageFunction[, arg])](https://playwright.dev/docs/api/class-locator#locator-evaluate-all),
* other [Locator](https://playwright.dev/docs/api/class-locator) helper methods and web-first assertions do a better
* job.
*
* The method finds all elements matching the specified selector within the page and passes an array of matched
* elements as a first argument to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression). Returns
* the result of
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression)
* invocation.
*
* If [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression) returns
* a [Promise], then
* [page.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all)
* would wait for the promise to resolve and return its value.
*
* **Usage**
*
* ```js
* const divCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 10);
* ```
*
* @param selector A selector to query for.
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all-option-expression).
*/
$$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any): Promise<R>;
/**
* Returns when the
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-wait-for-function-option-expression) returns a
* truthy value. It resolves to a JSHandle of the truthy value.
*
* **Usage**
*
* The
* [page.waitForFunction(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-wait-for-function)
* can be used to observe viewport size change:
*
* ```js
* const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
*
* (async () => {
* const browser = await webkit.launch();
* const page = await browser.newPage();
* const watchDog = page.waitForFunction(() => window.innerWidth < 100);
* await page.setViewportSize({ width: 50, height: 50 });
* await watchDog;
* await browser.close();
* })();
* ```
*
* To pass an argument to the predicate of
* [page.waitForFunction(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-wait-for-function)
* function:
*
* ```js
* const selector = '.foo';
* await page.waitForFunction(selector => !!document.querySelector(selector), selector);
* ```
*
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-wait-for-function-option-expression).
* @param options
*/
waitForFunction<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg, options?: PageWaitForFunctionOptions): Promise<SmartHandle<R>>;
/**
* Returns when the
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-wait-for-function-option-expression) returns a
* truthy value. It resolves to a JSHandle of the truthy value.
*
* **Usage**
*
* The
* [page.waitForFunction(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-wait-for-function)
* can be used to observe viewport size change:
*
* ```js
* const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
*
* (async () => {
* const browser = await webkit.launch();
* const page = await browser.newPage();
* const watchDog = page.waitForFunction(() => window.innerWidth < 100);
* await page.setViewportSize({ width: 50, height: 50 });
* await watchDog;
* await browser.close();
* })();
* ```
*
* To pass an argument to the predicate of
* [page.waitForFunction(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#page-wait-for-function)
* function:
*
* ```js
* const selector = '.foo';
* await page.waitForFunction(selector => !!document.querySelector(selector), selector);
* ```
*
* @param pageFunction Function to be evaluated in the page context.
* @param arg Optional argument to pass to
* [`pageFunction`](https://playwright.dev/docs/api/class-page#page-wait-for-function-option-expression).
* @param options
*/
waitForFunction<R>(pageFunction: PageFunction<void, R>, arg?: any, options?: PageWaitForFunctionOptions): Promise<SmartHandle<R>>;
/**
* **NOTE** Use web assertions that assert visibility or a locator-based
* [locator.waitFor([options])](https://playwright.dev/docs/api/class-locator#locator-wait-for) instead. Read more
* about [locators](https://playwright.dev/docs/locators).
*
* Returns when element specified by selector satisfies
* [`state`](https://playwright.dev/docs/api/class-page#page-wait-for-selector-option-state) option. Returns `null` if
* waiting for `hidden` or `detached`.
*
* **NOTE** Playwright automatically waits for element to be ready before performing an action. Using
* [Locator](https://playwright.dev/docs/api/class-locator) objects and web-first assertions makes the code
* wait-for-selector-free.
*
* Wait for the [`selector`](https://playwright.dev/docs/api/class-page#page-wait-for-selector-option-selector) to
* satisfy [`state`](https://playwright.dev/docs/api/class-page#page-wait-for-selector-option-state) option (either
* appear/disappear from dom, or become visible/hidden). If at the moment of calling the method
* [`selector`](https://playwright.dev/docs/api/class-page#page-wait-for-selector-option-selector) already satisfies
* the condition, the method will return immediately. If the selector doesn't satisfy the condition for the
* [`timeout`](https://playwright.dev/docs/api/class-page#page-wait-for-selector-option-timeout) milliseconds, the
* function will throw.
*
* **Usage**
*
* This method works across navigations:
*
* ```js
* const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
*
* (async () => {
* const browser = await chromium.launch();
* const page = await browser.newPage();
* for (const currentURL of ['https://google.com', 'https://bbc.com']) {
* await page.goto(currentURL);
* const element = await page.waitForSelector('img');
* console.log('Loaded image: ' + await element.getAttribute('src'));
* }
* await browser.close();
* })();
* ```
*
* @param selector A selector to query for.
* @param options
*/
waitForSelector<K extends keyof HTMLElementTagNameMap>(selector: K, options?: PageWaitForSelectorOptionsNotHidden): Promise<ElementHandleForTag<K>>;
/**
* **NOTE** Use web assertions that assert visibility or a locator-based
* [locator.waitFor([options])](https://playwright.dev/docs/api/class-locator#locator-wait-for) instead. Read more
* about [locators](https://playwright.dev/docs/locators).
*
* Returns when element specified by selector satisfies
* [`state`](https://playwright.dev/docs/api/class-page#page-wait-for-selector-option-state) option. Returns `null` if
* waiting for `hidden` or `detached`.
*
* **NOTE** Playwright automatically waits for element to be ready before performing an action. Using
* [Locator](https://playwright.dev/docs/api/class-locator) objects and web-first assertions makes the code
* wait-for-selector-free.
*
* Wait for the [`selector`](https://playwright.dev/docs/api/class-page#page-wait-for-selector-option-selector) to
* satisfy [`state`](https://playwright.dev/docs/api/class-page#page-wait-for-selector-option-state) option (either
* appear/disappear from dom, or become visible/hidden). If at the moment of calling the method
* [`selector`](https://playwright.dev/docs/api/class-page#page-wait-for-selector-option-selector) already satisfies
* the condition, the method will return immediately. If the selector doesn't satisfy the condition for the
* [`timeout`](https://playwright.dev/docs/api/class-page#page-wait-for-selector-option-timeout) milliseconds, the
* function will throw.
*
* **Usage**
*
* This method works across navigations:
*
* ```js
* const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
*
* (async () => {
* const browser = await chromium.launch();
* const page = await browser.newPage();
* for (const currentURL of ['https://google.com', 'https://bbc.com']) {
* await page.goto(currentURL);
* const element = await page.waitForSelector('img');
* console.log('Loaded image: ' + await element.getAttribute('src'));
* }
* await browser.close();
* })();
* ```
*
* @param selector A selector to query for.
* @param options
*/
waitForSelector(selector: string, options?: PageWaitForSelectorOptionsNotHidden): Promise<ElementHandle<SVGElement | HTMLElement>>;
/**
* **NOTE** Use web assertions that assert visibility or a locator-based
* [locator.waitFor([options])](https://playwright.dev/docs/api/class-locator#locator-wait-for) instead. Read more
* about [locators](https://playwright.dev/docs/locators).
*
* Returns when element specified by selector satisfies
* [`state`](https://playwright.dev/docs/api/class-page#page-wait-for-selector-option-state) option. Returns `null` if
* waiting for `hidden` or `detached`.
*
* **NOTE** Playwright automatically waits for element to be ready before performing an action. Using
* [Locator](https://playwright.dev/docs/api/class-locator) objects and web-first assertions makes the code
* wait-for-selector-free.
*
* Wait for the [`selector`](https://playwright.dev/docs/api/class-page#page-wait-for-selector-option-selector) to
* satisfy [`state`](https://playwright.dev/docs/api/class-page#page-wait-for-selector-option-state) option (either
* appear/disappear from dom, or become visible/hidden). If at the moment of calling the method
* [`selector`](https://playwright.dev/docs/api/class-page#page-wait-for-selector-option-selector) already satisfies
* the condition, the method will return immediately. If the selector doesn't satisfy the condition for the
* [`timeout`](https://playwright.dev/docs/api/class-page#page-wait-for-selector-option-timeout) milliseconds, the
* function will throw.
*
* **Usage**
*
* This method works across navigations:
*
* ```js
* const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
*
* (async () => {
* const browser = await chromium.launch();
* const page = await browser.newPage();
* for (const currentURL of ['https://google.com', 'https://bbc.com']) {
* await page.goto(currentURL);
* const element = await page.waitForSelector('img');
* console.log('Loaded image: ' + await element.getAttribute('src'));
* }
* await browser.close();
* })();
* ```
*
* @param selector A selector to query for.
* @param options
*/
waitForSelector<K extends keyof HTMLElementTagNameMap>(selector: K, options: PageWaitForSelectorOptions): Promise<ElementHandleForTag<K> | null>;
/**
* **NOTE** Use web assertions that assert visibility or a locator-based
* [locator.waitFor([options])](https://playwright.dev/docs/api/class-locator#locator-wait-for) instead. Read more
* about [locators](https://playwright.dev/docs/locators).
*
* Returns when element specified by selector satisfies
* [`state`](https://playwright.dev/docs/api/class-page#page-wait-for-selector-option-state) option. Returns `null` if
* waiting for `hidden` or `detached`.
*
* **NOTE** Playwright automatically waits for element to be ready before performing an action. Using
* [Locator](https://playwright.dev/docs/api/class-locator) objects and web-first assertions makes the code
* wait-for-selector-free.
*
* Wait for the [`selector`](https://playwright.dev/docs/api/class-page#page-wait-for-selector-option-selector) to
* satisfy [`state`](https://playwright.dev/docs/api/class-page#page-wait-for-selector-option-state) option (either
* appear/disappear from dom, or become visible/hidden). If at the moment of calling the method
* [`selector`](https://playwright.dev/docs/api/class-page#page-wait-for-selector-option-selector) already satisfies
* the condition, the method will return immediately. If the selector doesn't satisfy the condition for the
* [`timeout`](https://playwright.dev/docs/api/class-page#page-wait-for-selector-option-timeout) milliseconds, the
* function will throw.
*
* **Usage**
*
* This method works across navigations:
*
* ```js
* const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
*
* (async () => {
* const browser = await chromium.launch();
* const page = await browser.newPage();
* for (const currentURL of ['https://google.com', 'https://bbc.com']) {
* await page.goto(currentURL);
* const element = await page.waitForSelector('img');
* console.log('Loaded image: ' + await element.getAttribute('src'));
* }
* await browser.close();
* })();
* ```
*
* @param selector A selector to query for.
* @param options
*/
waitForSelector(selector: string, options: PageWaitForSelectorOptions): Promise<null|ElementHandle<SVGElement | HTMLElement>>;
/**
* The method adds a function called
* [`name`](https://playwright.dev/docs/api/class-page#page-expose-binding-option-name) on the `window` object of
* every frame in this page. When called, the function executes
* [`callback`](https://playwright.dev/docs/api/class-page#page-expose-binding-option-callback) and returns a
* [Promise] which resolves to the return value of
* [`callback`](https://playwright.dev/docs/api/class-page#page-expose-binding-option-callback). If the
* [`callback`](https://playwright.dev/docs/api/class-page#page-expose-binding-option-callback) returns a [Promise],
* it will be awaited.
*
* The first argument of the
* [`callback`](https://playwright.dev/docs/api/class-page#page-expose-binding-option-callback) function contains
* information about the caller: `{ browserContext: BrowserContext, page: Page, frame: Frame }`.
*
* See
* [browserContext.exposeBinding(name, callback[, options])](https://playwright.dev/docs/api/class-browsercontext#browser-context-expose-binding)
* for the context-wide version.
*
* **NOTE** Functions installed via
* [page.exposeBinding(name, callback[, options])](https://playwright.dev/docs/api/class-page#page-expose-binding)
* survive navigations.
*
* **Usage**
*
* An example of exposing page URL to all frames in a page:
*
* ```js
* const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
*
* (async () => {
* const browser = await webkit.launch({ headless: false });
* const context = await browser.newContext();
* const page = await context.newPage();
* await page.exposeBinding('pageURL', ({ page }) => page.url());
* await page.setContent(`
* <script>
* async function onClick() {
* document.querySelector('div').textContent = await window.pageURL();
* }
* </script>
* <button onclick="onClick()">Click me</button>
* <div></div>
* `);
* await page.click('button');
* })();
* ```
*
* @param name Name of the function on the window object.
* @param callback Callback function that will be called in the Playwright's context.
* @param options
*/
exposeBinding(name: string, playwrightBinding: (source: BindingSource, arg: JSHandle) => any, options: { handle: true }): Promise<void>;
/**
* The method adds a function called
* [`name`](https://playwright.dev/docs/api/class-page#page-expose-binding-option-name) on the `window` object of
* every frame in this page. When called, the function executes
* [`callback`](https://playwright.dev/docs/api/class-page#page-expose-binding-option-callback) and returns a
* [Promise] which resolves to the return value of
* [`callback`](https://playwright.dev/docs/api/class-page#page-expose-binding-option-callback). If the
* [`callback`](https://playwright.dev/docs/api/class-page#page-expose-binding-option-callback) returns a [Promise],
* it will be awaited.
*
* The first argument of the
* [`callback`](https://playwright.dev/docs/api/class-page#page-expose-binding-option-callback) function contains
* information about the caller: `{ browserContext: BrowserContext, page: Page, frame: Frame }`.
*
* See
* [browserContext.exposeBinding(name, callback[, options])](https://playwright.dev/docs/api/class-browsercontext#browser-context-expose-binding)
* for the context-wide version.
*
* **NOTE** Functions installed via
* [page.exposeBinding(name, callback[, options])](https://playwright.dev/docs/api/class-page#page-expose-binding)
* survive navigations.
*
* **Usage**
*
* An example of exposing page URL to all frames in a page:
*
* ```js
* const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
*
* (async () => {
* const browser = await webkit.launch({ headless: false });
* const context = await browser.newContext();
* const page = await context.newPage();
* await page.exposeBinding('pageURL', ({ page }) => page.url());
* await page.setContent(`
* <script>
* async function onClick() {
* document.querySelector('div').textContent = await window.pageURL();
* }
* </script>
* <button onclick="onClick()">Click me</button>
* <div></div>
* `);
* await page.click('button');
* })();
* ```
*
* @param name Name of the function on the window object.
* @param callback Callback function that will be called in the Playwright's context.
* @param options
*/
exposeBinding(name: string, playwrightBinding: (source: BindingSource, ...args: any[]) => any, options?: { handle?: boolean }): Promise<void>;
/**
* Removes all the listeners of the given type (or all registered listeners if no type given). Allows to wait for
* async listeners to complete or to ignore subsequent errors from these listeners.
*
* **Usage**
*
* ```js
* page.on('request', async request => {
* const response = await request.response();
* const body = await response.body();
* console.log(body.byteLength);
* });
* await page.goto('https://playwright.dev', { waitUntil: 'domcontentloaded' });
* // Waits for all the reported 'request' events to resolve.
* await page.removeAllListeners('request', { behavior: 'wait' });
* ```
*
* @param type
* @param options
*/
removeAllListeners(type?: string): this;
/**
* Removes all the listeners of the given type (or all registered listeners if no type given). Allows to wait for
* async listeners to complete or to ignore subsequent errors from these listeners.
*
* **Usage**
*
* ```js
* page.on('request', async request => {
* const response = await request.response();
* const body = await response.body();
* console.log(body.byteLength);
* });
* await page.goto('https://playwright.dev', { waitUntil: 'domcontentloaded' });
* // Waits for all the reported 'request' events to resolve.
* await page.removeAllListeners('request', { behavior: 'wait' });
* ```
*
* @param type
* @param options
*/
removeAllListeners(type: string | undefined, options: {
/**
* Specifies whether to wait for already running listeners and what to do if they throw errors:
* - `'default'` - do not wait for current listener calls (if any) to finish, if the listener throws, it may result in unhandled error
* - `'wait'` - wait for current listener calls (if any) to finish
* - `'ignoreErrors'` - do not wait for current listener calls (if any) to finish, all errors thrown by the listeners after removal are silently caught
*/
behavior?: 'wait'|'ignoreErrors'|'default'
}): Promise<void>;
/**
* Emitted when the page closes.
*/
on(event: 'close', listener: (page: Page) => any): this;
/**
* Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`.
*
* The arguments passed into `console.log` are available on the
* [ConsoleMessage](https://playwright.dev/docs/api/class-consolemessage) event handler argument.
*
*