docs: annotate evaluate(pageFunction) js-specific (#4954)

This commit is contained in:
Pavel Feldman 2021-01-08 16:17:54 -08:00 committed by GitHub
parent 31d980fc92
commit b7e0b1b393
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 263 additions and 129 deletions

View File

@ -66,6 +66,7 @@ expect(await tweetHandle.$eval('.retweets', node => node.innerText)).toBe('10');
### param: ElementHandle.$eval.selector = %%-query-selector-%% ### param: ElementHandle.$eval.selector = %%-query-selector-%%
### param: ElementHandle.$eval.pageFunction ### param: ElementHandle.$eval.pageFunction
* langs: js
- `pageFunction` <[function]\([Element]\)> - `pageFunction` <[function]\([Element]\)>
Function to be evaluated in browser context Function to be evaluated in browser context
@ -106,6 +107,7 @@ expect(await feedHandle.$$eval('.tweet', nodes => nodes.map(n => n.innerText))).
### param: ElementHandle.$$eval.selector = %%-query-selector-%% ### param: ElementHandle.$$eval.selector = %%-query-selector-%%
### param: ElementHandle.$$eval.pageFunction ### param: ElementHandle.$$eval.pageFunction
* langs: js
- `pageFunction` <[function]\([Array]<[Element]>\)> - `pageFunction` <[function]\([Array]<[Element]>\)>
Function to be evaluated in browser context Function to be evaluated in browser context

View File

@ -86,6 +86,7 @@ const html = await frame.$eval('.main-container', (e, suffix) => e.outerHTML + s
### param: Frame.$eval.selector = %%-query-selector-%% ### param: Frame.$eval.selector = %%-query-selector-%%
### param: Frame.$eval.pageFunction ### param: Frame.$eval.pageFunction
* langs: js
- `pageFunction` <[function]\([Element]\)> - `pageFunction` <[function]\([Element]\)>
Function to be evaluated in browser context Function to be evaluated in browser context
@ -118,6 +119,7 @@ const divsCounts = await frame.$$eval('div', (divs, min) => divs.length >= min,
### param: Frame.$$eval.selector = %%-query-selector-%% ### param: Frame.$$eval.selector = %%-query-selector-%%
### param: Frame.$$eval.pageFunction ### param: Frame.$$eval.pageFunction
* langs: js
- `pageFunction` <[function]\([Array]<[Element]>\)> - `pageFunction` <[function]\([Array]<[Element]>\)>
Function to be evaluated in browser context Function to be evaluated in browser context
@ -134,12 +136,25 @@ Returns the added tag when the script's onload fires or when the script content
Adds a `<script>` tag into the page with the desired url or content. Adds a `<script>` tag into the page with the desired url or content.
### param: Frame.addScriptTag.params ### option: Frame.addScriptTag.url
- `params` <[Object]> - `url` <[string]>
- `url` <[string]> URL of a script to be added. Optional.
- `path` <[path]> Path to the JavaScript file to be injected into frame. If `path` is a relative path, then it is resolved relative to the current working directory. Optional. URL of a script to be added.
- `content` <[string]> Raw JavaScript content to be injected into frame. Optional.
- `type` <[string]> Script type. Use 'module' in order to load a Javascript ES6 module. See [script](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) for more details. Optional. ### option: Frame.addScriptTag.path
- `path` <[path]>
Path to the JavaScript file to be injected into frame. If `path` is a relative path, then it is resolved relative to the current working directory.
### option: Frame.addScriptTag.content
- `content` <[string]>
Raw JavaScript content to be injected into frame.
### option: Frame.addScriptTag.type
- `type` <[string]>
Script type. Use 'module' in order to load a Javascript ES6 module. See [script](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) for more details.
## async method: Frame.addStyleTag ## async method: Frame.addStyleTag
- returns: <[ElementHandle]> - returns: <[ElementHandle]>
@ -149,11 +164,20 @@ Returns the added tag when the stylesheet's onload fires or when the CSS content
Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the
content. content.
### param: Frame.addStyleTag.params ### option: Frame.addStyleTag.url
- `params` <[Object]> - `url` <[string]>
- `url` <[string]> URL of the `<link>` tag. Optional.
- `path` <[path]> Path to the CSS file to be injected into frame. If `path` is a relative path, then it is resolved relative to the current working directory. Optional. URL of the `<link>` tag.
- `content` <[string]> Raw CSS content to be injected into frame. Optional.
### option: Frame.addStyleTag.path
- `path` <[path]>
Path to the CSS file to be injected into frame. If `path` is a relative path, then it is resolved relative to the current working directory.
### option: Frame.addStyleTag.content
- `content` <[string]>
Raw CSS content to be injected into frame.
## async method: Frame.check ## async method: Frame.check
@ -324,6 +348,7 @@ await bodyHandle.dispose();
``` ```
### param: Frame.evaluate.pageFunction ### param: Frame.evaluate.pageFunction
* langs: js
- `pageFunction` <[function]|[string]> - `pageFunction` <[function]|[string]>
Function to be evaluated in browser context Function to be evaluated in browser context
@ -365,6 +390,7 @@ await resultHandle.dispose();
``` ```
### param: Frame.evaluateHandle.pageFunction ### param: Frame.evaluateHandle.pageFunction
* langs: js
- `pageFunction` <[function]|[string]> - `pageFunction` <[function]|[string]>
Function to be evaluated in the page context Function to be evaluated in the page context
@ -790,6 +816,7 @@ await frame.waitForFunction(selector => !!document.querySelector(selector), sele
``` ```
### param: Frame.waitForFunction.pageFunction ### param: Frame.waitForFunction.pageFunction
* langs: js
- `pageFunction` <[function]|[string]> - `pageFunction` <[function]|[string]>
Function to be evaluated in browser context Function to be evaluated in browser context

View File

@ -42,6 +42,7 @@ expect(await tweetHandle.evaluate((node, suffix) => node.innerText, ' retweets')
``` ```
### param: JSHandle.evaluate.pageFunction ### param: JSHandle.evaluate.pageFunction
* langs: js
- `pageFunction` <[function]> - `pageFunction` <[function]>
Function to be evaluated in browser context Function to be evaluated in browser context
@ -67,6 +68,7 @@ for the promise to resolve and return its value.
See [`method: Page.evaluateHandle`] for more details. See [`method: Page.evaluateHandle`] for more details.
### param: JSHandle.evaluateHandle.pageFunction ### param: JSHandle.evaluateHandle.pageFunction
* langs: js
- `pageFunction` <[function]|[string]> - `pageFunction` <[function]|[string]>
Function to be evaluated Function to be evaluated

View File

@ -258,6 +258,7 @@ Shortcut for main frame's [`method: Frame.$eval`].
### param: Page.$eval.selector = %%-query-selector-%% ### param: Page.$eval.selector = %%-query-selector-%%
### param: Page.$eval.pageFunction ### param: Page.$eval.pageFunction
* langs: js
- `pageFunction` <[function]\([Element]\)> - `pageFunction` <[function]\([Element]\)>
Function to be evaluated in browser context Function to be evaluated in browser context
@ -287,6 +288,7 @@ const divsCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 1
### param: Page.$$eval.selector = %%-query-selector-%% ### param: Page.$$eval.selector = %%-query-selector-%%
### param: Page.$$eval.pageFunction ### param: Page.$$eval.pageFunction
* langs: js
- `pageFunction` <[function]\([Array]<[Element]>\)> - `pageFunction` <[function]\([Array]<[Element]>\)>
Function to be evaluated in browser context Function to be evaluated in browser context
@ -344,12 +346,25 @@ fires or when the script content was injected into frame.
Shortcut for main frame's [`method: Frame.addScriptTag`]. Shortcut for main frame's [`method: Frame.addScriptTag`].
### param: Page.addScriptTag.params ### option: Page.addScriptTag.url
- `params` <[Object]> - `url` <[string]>
- `url` <[string]> URL of a script to be added. Optional.
- `path` <[path]> Path to the JavaScript file to be injected into frame. If `path` is a relative path, then it is resolved relative to the current working directory. Optional. URL of a script to be added.
- `content` <[string]> Raw JavaScript content to be injected into frame. Optional.
- `type` <[string]> Script type. Use 'module' in order to load a Javascript ES6 module. See [script](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) for more details. Optional. ### option: Page.addScriptTag.path
- `path` <[path]>
Path to the JavaScript file to be injected into frame. If `path` is a relative path, then it is resolved relative to the current working directory.
### option: Page.addScriptTag.content
- `content` <[string]>
Raw JavaScript content to be injected into frame.
### option: Page.addScriptTag.type
- `type` <[string]>
Script type. Use 'module' in order to load a Javascript ES6 module. See [script](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) for more details.
## async method: Page.addStyleTag ## async method: Page.addStyleTag
- returns: <[ElementHandle]> - returns: <[ElementHandle]>
@ -359,11 +374,20 @@ content. Returns the added tag when the stylesheet's onload fires or when the CS
Shortcut for main frame's [`method: Frame.addStyleTag`]. Shortcut for main frame's [`method: Frame.addStyleTag`].
### param: Page.addStyleTag.params ### option: Page.addStyleTag.url
- `params` <[Object]> - `url` <[string]>
- `url` <[string]> URL of the `<link>` tag. Optional.
- `path` <[path]> Path to the CSS file to be injected into frame. If `path` is a relative path, then it is resolved relative to the current working directory. Optional. URL of the `<link>` tag.
- `content` <[string]> Raw CSS content to be injected into frame. Optional.
### option: Page.addStyleTag.path
- `path` <[path]>
Path to the CSS file to be injected into frame. If `path` is a relative path, then it is resolved relative to the current working directory.
### option: Page.addStyleTag.content
- `content` <[string]>
Raw CSS content to be injected into frame.
## async method: Page.bringToFront ## async method: Page.bringToFront
@ -613,6 +637,7 @@ await bodyHandle.dispose();
Shortcut for main frame's [`method: Frame.evaluate`]. Shortcut for main frame's [`method: Frame.evaluate`].
### param: Page.evaluate.pageFunction ### param: Page.evaluate.pageFunction
* langs: js
- `pageFunction` <[function]|[string]> - `pageFunction` <[function]|[string]>
Function to be evaluated in the page context Function to be evaluated in the page context
@ -649,6 +674,7 @@ await resultHandle.dispose();
``` ```
### param: Page.evaluateHandle.pageFunction ### param: Page.evaluateHandle.pageFunction
* langs: js
- `pageFunction` <[function]|[string]> - `pageFunction` <[function]|[string]>
Function to be evaluated in the page context Function to be evaluated in the page context
@ -1615,6 +1641,7 @@ await page.waitForFunction(selector => !!document.querySelector(selector), selec
Shortcut for main frame's [`method: Frame.waitForFunction`]. Shortcut for main frame's [`method: Frame.waitForFunction`].
### param: Page.waitForFunction.pageFunction ### param: Page.waitForFunction.pageFunction
* langs: js
- `pageFunction` <[function]|[string]> - `pageFunction` <[function]|[string]>
Function to be evaluated in browser context Function to be evaluated in browser context

View File

@ -44,14 +44,26 @@ await page.route('**/*', (route, request) => {
}); });
``` ```
### param: Route.continue.overrides ### option: Route.continue.url
- `overrides` <[Object]> - `url` <[string]>
- `url` <[string]> If set changes the request URL. New URL must have same protocol as original one.
- `method` <[string]> If set changes the request method (e.g. GET or POST) If set changes the request URL. New URL must have same protocol as original one.
- `postData` <[string]|[Buffer]> If set changes the post data of request
- `headers` <[Object]<[string], [string]>> If set changes the request HTTP headers. Header values will be converted to a string. ### option: Route.continue.method
- `method` <[string]>
If set changes the request method (e.g. GET or POST)
### option: Route.continue.postData
- `postData` <[string]|[Buffer]>
If set changes the post data of request
### option: Route.continue.headers
- `headers` <[Object]<[string], [string]>>
If set changes the request HTTP headers. Header values will be converted to a string.
Optional request overrides, can override following properties:
## async method: Route.fulfill ## async method: Route.fulfill
@ -75,15 +87,30 @@ An example of serving static file:
await page.route('**/xhr_endpoint', route => route.fulfill({ path: 'mock_data.json' })); await page.route('**/xhr_endpoint', route => route.fulfill({ path: 'mock_data.json' }));
``` ```
### param: Route.fulfill.response ### option: Route.fulfill.status
- `response` <[Object]> - `status` <[int]>
- `status` <[int]> Response status code, defaults to `200`.
- `headers` <[Object]<[string], [string]>> Optional response headers. Header values will be converted to a string.
- `contentType` <[string]> If set, equals to setting `Content-Type` response header.
- `body` <[string]|[Buffer]> Optional response body.
- `path` <[path]> Optional file path to respond with. The content type will be inferred from file extension. If `path` is a relative path, then it is resolved relative to the current working directory.
Response that will fulfill this route's request. Response status code, defaults to `200`.
### option: Route.fulfill.headers
- `headers` <[Object]<[string], [string]>>
Response headers. Header values will be converted to a string.
### option: Route.fulfill.contentType
- `contentType` <[string]>
If set, equals to setting `Content-Type` response header.
### option: Route.fulfill.body
- `body` <[string]|[Buffer]>
Response body.
### option: Route.fulfill.path
- `path` <[path]>
File path to respond with. The content type will be inferred from file extension. If `path` is a relative path, then it is resolved relative to the current working directory.
## method: Route.request ## method: Route.request
- returns: <[Request]> - returns: <[Request]>

View File

@ -33,6 +33,7 @@ If the function passed to the `worker.evaluate` returns a non-[Serializable] val
`-0`, `NaN`, `Infinity`, `-Infinity`, and bigint literals. `-0`, `NaN`, `Infinity`, `-Infinity`, and bigint literals.
### param: Worker.evaluate.pageFunction ### param: Worker.evaluate.pageFunction
* langs: js
- `pageFunction` <[function]|[string]> - `pageFunction` <[function]|[string]>
Function to be evaluated in the worker context Function to be evaluated in the worker context
@ -54,6 +55,7 @@ If the function passed to the `worker.evaluateHandle` returns a [Promise], then
the promise to resolve and return its value. the promise to resolve and return its value.
### param: Worker.evaluateHandle.pageFunction ### param: Worker.evaluateHandle.pageFunction
* langs: js
- `pageFunction` <[function]|[string]> - `pageFunction` <[function]|[string]>
Function to be evaluated in the page context Function to be evaluated in the page context

View File

@ -316,6 +316,19 @@ Receives the event data and resolves to truthy value when the waiting should res
Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
The default value can be changed by using the [`method: BrowserContext.setDefaultTimeout`]. The default value can be changed by using the [`method: BrowserContext.setDefaultTimeout`].
## python-evaluate-expression
* langs: python
- `expression` <string>
JavaScript expression to be evaluated in the browser context. If it looks like a function declaration,
it is interpreted as a function. Otherwise, evaluated as an expression.
## python-evaluate-force-expression
* langs: python
- `force_expr` <boolean>
Whether to treat given `expression` as JavaScript evaluate expression, even though it looks like an arrow function.
Optional.
## shared-context-params-list ## shared-context-params-list
- %%-context-option-acceptdownloads-%% - %%-context-option-acceptdownloads-%%

View File

@ -102,3 +102,37 @@ value. Optional.
### option: Page.waitForEvent.timeout = %%-python-wait-for-event-timeout-%% ### option: Page.waitForEvent.timeout = %%-python-wait-for-event-timeout-%%
### option: WebSocket.waitForEvent.predicate = %%-python-wait-for-event-predicate-%% ### option: WebSocket.waitForEvent.predicate = %%-python-wait-for-event-predicate-%%
### option: WebSocket.waitForEvent.timeout = %%-python-wait-for-event-timeout-%% ### option: WebSocket.waitForEvent.timeout = %%-python-wait-for-event-timeout-%%
### param: ElementHandle.$eval.expression = %%-python-evaluate-expression-%%
### param: ElementHandle.$$eval.expression = %%-python-evaluate-expression-%%
### param: Frame.$eval.expression = %%-python-evaluate-expression-%%
### param: Frame.$$eval.expression = %%-python-evaluate-expression-%%
### param: Frame.evaluate.expression = %%-python-evaluate-expression-%%
### param: Frame.evaluateHandle.expression = %%-python-evaluate-expression-%%
### param: Frame.waitForFunction.expression = %%-python-evaluate-expression-%%
### param: JSHandle.evaluate.expression = %%-python-evaluate-expression-%%
### param: JSHandle.evaluateHandle.expression = %%-python-evaluate-expression-%%
### param: Page.$eval.expression = %%-python-evaluate-expression-%%
### param: Page.$$eval.expression = %%-python-evaluate-expression-%%
### param: Page.evaluate.expression = %%-python-evaluate-expression-%%
### param: Page.evaluateHandle.expression = %%-python-evaluate-expression-%%
### param: Page.waitForFunction.expression = %%-python-evaluate-expression-%%
### param: Worker.evaluate.expression = %%-python-evaluate-expression-%%
### param: Worker.evaluateHandle.expression = %%-python-evaluate-expression-%%
### param: ElementHandle.$eval.expression = %%-python-evaluate-force-expression-%%
### param: ElementHandle.$$eval.expression = %%-python-evaluate-force-expression-%%
### param: Frame.$eval.expression = %%-python-evaluate-force-expression-%%
### param: Frame.$$eval.expression = %%-python-evaluate-force-expression-%%
### param: Frame.evaluate.expression = %%-python-evaluate-force-expression-%%
### param: Frame.evaluateHandle.expression = %%-python-evaluate-force-expression-%%
### param: Frame.waitForFunction.expression = %%-python-evaluate-force-expression-%%
### param: JSHandle.evaluate.expression = %%-python-evaluate-force-expression-%%
### param: JSHandle.evaluateHandle.expression = %%-python-evaluate-force-expression-%%
### param: Page.$eval.expression = %%-python-evaluate-force-expression-%%
### param: Page.$$eval.expression = %%-python-evaluate-force-expression-%%
### param: Page.evaluate.expression = %%-python-evaluate-force-expression-%%
### param: Page.evaluateHandle.expression = %%-python-evaluate-force-expression-%%
### param: Page.waitForFunction.expression = %%-python-evaluate-force-expression-%%
### param: Worker.evaluate.expression = %%-python-evaluate-force-expression-%%
### param: Worker.evaluateHandle.expression = %%-python-evaluate-force-expression-%%

View File

@ -284,9 +284,9 @@ export class Frame extends ChannelOwner<channels.FrameChannel, channels.FrameIni
return this._detached; return this._detached;
} }
async addScriptTag(params: { url?: string, path?: string, content?: string, type?: string }): Promise<ElementHandle> { async addScriptTag(options: { url?: string, path?: string, content?: string, type?: string } = {}): Promise<ElementHandle> {
return this._wrapApiCall(this._apiName('addScriptTag'), async () => { return this._wrapApiCall(this._apiName('addScriptTag'), async () => {
const copy = { ...params }; const copy = { ...options };
if (copy.path) { if (copy.path) {
copy.content = (await fsReadFileAsync(copy.path)).toString(); copy.content = (await fsReadFileAsync(copy.path)).toString();
copy.content += '//# sourceURL=' + copy.path.replace(/\n/g, ''); copy.content += '//# sourceURL=' + copy.path.replace(/\n/g, '');
@ -295,9 +295,9 @@ export class Frame extends ChannelOwner<channels.FrameChannel, channels.FrameIni
}); });
} }
async addStyleTag(params: { url?: string; path?: string; content?: string; }): Promise<ElementHandle> { async addStyleTag(options: { url?: string; path?: string; content?: string; } = {}): Promise<ElementHandle> {
return this._wrapApiCall(this._apiName('addStyleTag'), async () => { return this._wrapApiCall(this._apiName('addStyleTag'), async () => {
const copy = { ...params }; const copy = { ...options };
if (copy.path) { if (copy.path) {
copy.content = (await fsReadFileAsync(copy.path)).toString(); copy.content = (await fsReadFileAsync(copy.path)).toString();
copy.content += '/*# sourceURL=' + copy.path.replace(/\n/g, '') + '*/'; copy.content += '/*# sourceURL=' + copy.path.replace(/\n/g, '') + '*/';

View File

@ -185,49 +185,49 @@ export class Route extends ChannelOwner<channels.RouteChannel, channels.RouteIni
await this._channel.abort({ errorCode }); await this._channel.abort({ errorCode });
} }
async fulfill(response: { status?: number, headers?: Headers, contentType?: string, body?: string | Buffer, path?: string }) { async fulfill(options: { status?: number, headers?: Headers, contentType?: string, body?: string | Buffer, path?: string } = {}) {
let body = ''; let body = '';
let isBase64 = false; let isBase64 = false;
let length = 0; let length = 0;
if (response.path) { if (options.path) {
const buffer = await util.promisify(fs.readFile)(response.path); const buffer = await util.promisify(fs.readFile)(options.path);
body = buffer.toString('base64'); body = buffer.toString('base64');
isBase64 = true; isBase64 = true;
length = buffer.length; length = buffer.length;
} else if (isString(response.body)) { } else if (isString(options.body)) {
body = response.body; body = options.body;
isBase64 = false; isBase64 = false;
length = Buffer.byteLength(body); length = Buffer.byteLength(body);
} else if (response.body) { } else if (options.body) {
body = response.body.toString('base64'); body = options.body.toString('base64');
isBase64 = true; isBase64 = true;
length = response.body.length; length = options.body.length;
} }
const headers: Headers = {}; const headers: Headers = {};
for (const header of Object.keys(response.headers || {})) for (const header of Object.keys(options.headers || {}))
headers[header.toLowerCase()] = String(response.headers![header]); headers[header.toLowerCase()] = String(options.headers![header]);
if (response.contentType) if (options.contentType)
headers['content-type'] = String(response.contentType); headers['content-type'] = String(options.contentType);
else if (response.path) else if (options.path)
headers['content-type'] = mime.getType(response.path) || 'application/octet-stream'; headers['content-type'] = mime.getType(options.path) || 'application/octet-stream';
if (length && !('content-length' in headers)) if (length && !('content-length' in headers))
headers['content-length'] = String(length); headers['content-length'] = String(length);
await this._channel.fulfill({ await this._channel.fulfill({
status: response.status || 200, status: options.status || 200,
headers: headersObjectToArray(headers), headers: headersObjectToArray(headers),
body, body,
isBase64 isBase64
}); });
} }
async continue(overrides: { url?: string, method?: string, headers?: Headers, postData?: string | Buffer } = {}) { async continue(options: { url?: string, method?: string, headers?: Headers, postData?: string | Buffer } = {}) {
const postDataBuffer = isString(overrides.postData) ? Buffer.from(overrides.postData, 'utf8') : overrides.postData; const postDataBuffer = isString(options.postData) ? Buffer.from(options.postData, 'utf8') : options.postData;
await this._channel.continue({ await this._channel.continue({
url: overrides.url, url: options.url,
method: overrides.method, method: options.method,
headers: overrides.headers ? headersObjectToArray(overrides.headers) : undefined, headers: options.headers ? headersObjectToArray(options.headers) : undefined,
postData: postDataBuffer ? postDataBuffer.toString('base64') : undefined, postData: postDataBuffer ? postDataBuffer.toString('base64') : undefined,
}); });
} }

View File

@ -296,12 +296,12 @@ export class Page extends ChannelOwner<channels.PageChannel, channels.PageInitia
return this._attributeToPage(() => this._mainFrame.$$(selector)); return this._attributeToPage(() => this._mainFrame.$$(selector));
} }
async addScriptTag(params: { url?: string; path?: string; content?: string; type?: string; }): Promise<ElementHandle> { async addScriptTag(options: { url?: string; path?: string; content?: string; type?: string; } = {}): Promise<ElementHandle> {
return this._attributeToPage(() => this._mainFrame.addScriptTag(params)); return this._attributeToPage(() => this._mainFrame.addScriptTag(options));
} }
async addStyleTag(params: { url?: string; path?: string; content?: string; }): Promise<ElementHandle> { async addStyleTag(options: { url?: string; path?: string; content?: string; } = {}): Promise<ElementHandle> {
return this._attributeToPage(() => this._mainFrame.addStyleTag(params)); return this._attributeToPage(() => this._mainFrame.addStyleTag(options));
} }
async exposeFunction(name: string, callback: Function) { async exposeFunction(name: string, callback: Function) {
@ -403,7 +403,7 @@ export class Page extends ChannelOwner<channels.PageChannel, channels.PageInitia
}); });
} }
async emulateMedia(params: { media?: 'screen' | 'print' | null, colorScheme?: 'dark' | 'light' | 'no-preference' | null }) { async emulateMedia(params: { media?: 'screen' | 'print' | null, colorScheme?: 'dark' | 'light' | 'no-preference' | null } = {}) {
return this._wrapApiCall('page.emulateMedia', async () => { return this._wrapApiCall('page.emulateMedia', async () => {
await this._channel.emulateMedia({ await this._channel.emulateMedia({
media: params.media === null ? 'null' : params.media, media: params.media === null ? 'null' : params.media,

126
types/types.d.ts vendored
View File

@ -1309,30 +1309,30 @@ export interface Page {
* *
* Shortcut for main frame's * Shortcut for main frame's
* [frame.addScriptTag()](https://github.com/microsoft/playwright/blob/master/docs/api.md#frameaddscripttag). * [frame.addScriptTag()](https://github.com/microsoft/playwright/blob/master/docs/api.md#frameaddscripttag).
* @param params * @param options
*/ */
addScriptTag(params: { addScriptTag(options?: {
/** /**
* URL of a script to be added. Optional. * Raw JavaScript content to be injected into frame.
*/
url?: string;
/**
* Path to the JavaScript file to be injected into frame. If `path` is a relative path, then it is resolved relative to the
* current working directory. Optional.
*/
path?: string;
/**
* Raw JavaScript content to be injected into frame. Optional.
*/ */
content?: string; content?: string;
/**
* Path to the JavaScript file to be injected into frame. If `path` is a relative path, then it is resolved relative to the
* current working directory.
*/
path?: string;
/** /**
* Script type. Use 'module' in order to load a Javascript ES6 module. See * Script type. Use 'module' in order to load a Javascript ES6 module. See
* [script](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) for more details. Optional. * [script](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) for more details.
*/ */
type?: string; type?: string;
/**
* URL of a script to be added.
*/
url?: string;
}): Promise<ElementHandle>; }): Promise<ElementHandle>;
/** /**
@ -1341,24 +1341,24 @@ export interface Page {
* *
* Shortcut for main frame's * Shortcut for main frame's
* [frame.addStyleTag()](https://github.com/microsoft/playwright/blob/master/docs/api.md#frameaddstyletag). * [frame.addStyleTag()](https://github.com/microsoft/playwright/blob/master/docs/api.md#frameaddstyletag).
* @param params * @param options
*/ */
addStyleTag(params: { addStyleTag(options?: {
/** /**
* URL of the `<link>` tag. Optional. * Raw CSS content to be injected into frame.
*/ */
url?: string; content?: string;
/** /**
* Path to the CSS file to be injected into frame. If `path` is a relative path, then it is resolved relative to the * Path to the CSS file to be injected into frame. If `path` is a relative path, then it is resolved relative to the
* current working directory. Optional. * current working directory.
*/ */
path?: string; path?: string;
/** /**
* Raw CSS content to be injected into frame. Optional. * URL of the `<link>` tag.
*/ */
content?: string; url?: string;
}): Promise<ElementHandle>; }): Promise<ElementHandle>;
/** /**
@ -3501,30 +3501,30 @@ export interface Frame {
* Returns the added tag when the script's onload fires or when the script content was injected into frame. * Returns the added tag when the script's onload fires or when the script content was injected into frame.
* *
* Adds a `<script>` tag into the page with the desired url or content. * Adds a `<script>` tag into the page with the desired url or content.
* @param params * @param options
*/ */
addScriptTag(params: { addScriptTag(options?: {
/** /**
* URL of a script to be added. Optional. * Raw JavaScript content to be injected into frame.
*/
url?: string;
/**
* Path to the JavaScript file to be injected into frame. If `path` is a relative path, then it is resolved relative to the
* current working directory. Optional.
*/
path?: string;
/**
* Raw JavaScript content to be injected into frame. Optional.
*/ */
content?: string; content?: string;
/**
* Path to the JavaScript file to be injected into frame. If `path` is a relative path, then it is resolved relative to the
* current working directory.
*/
path?: string;
/** /**
* Script type. Use 'module' in order to load a Javascript ES6 module. See * Script type. Use 'module' in order to load a Javascript ES6 module. See
* [script](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) for more details. Optional. * [script](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) for more details.
*/ */
type?: string; type?: string;
/**
* URL of a script to be added.
*/
url?: string;
}): Promise<ElementHandle>; }): Promise<ElementHandle>;
/** /**
@ -3532,24 +3532,24 @@ export interface Frame {
* *
* Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the * Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the
* content. * content.
* @param params * @param options
*/ */
addStyleTag(params: { addStyleTag(options?: {
/** /**
* URL of the `<link>` tag. Optional. * Raw CSS content to be injected into frame.
*/ */
url?: string; content?: string;
/** /**
* Path to the CSS file to be injected into frame. If `path` is a relative path, then it is resolved relative to the * Path to the CSS file to be injected into frame. If `path` is a relative path, then it is resolved relative to the
* current working directory. Optional. * current working directory.
*/ */
path?: string; path?: string;
/** /**
* Raw CSS content to be injected into frame. Optional. * URL of the `<link>` tag.
*/ */
content?: string; url?: string;
}): Promise<ElementHandle>; }): Promise<ElementHandle>;
/** /**
@ -8855,13 +8855,13 @@ export interface Route {
* }); * });
* ``` * ```
* *
* @param overrides Optional request overrides, can override following properties: * @param options
*/ */
continue(overrides?: { continue(options?: {
/** /**
* If set changes the request URL. New URL must have same protocol as original one. * If set changes the request HTTP headers. Header values will be converted to a string.
*/ */
url?: string; headers?: { [key: string]: string; };
/** /**
* If set changes the request method (e.g. GET or POST) * If set changes the request method (e.g. GET or POST)
@ -8874,9 +8874,9 @@ export interface Route {
postData?: string|Buffer; postData?: string|Buffer;
/** /**
* If set changes the request HTTP headers. Header values will be converted to a string. * If set changes the request URL. New URL must have same protocol as original one.
*/ */
headers?: { [key: string]: string; }; url?: string;
}): Promise<void>; }): Promise<void>;
/** /**
@ -8900,18 +8900,13 @@ export interface Route {
* await page.route('**\/xhr_endpoint', route => route.fulfill({ path: 'mock_data.json' })); * await page.route('**\/xhr_endpoint', route => route.fulfill({ path: 'mock_data.json' }));
* ``` * ```
* *
* @param response Response that will fulfill this route's request. * @param options
*/ */
fulfill(response: { fulfill(options?: {
/** /**
* Response status code, defaults to `200`. * Response body.
*/ */
status?: number; body?: string|Buffer;
/**
* Optional response headers. Header values will be converted to a string.
*/
headers?: { [key: string]: string; };
/** /**
* If set, equals to setting `Content-Type` response header. * If set, equals to setting `Content-Type` response header.
@ -8919,15 +8914,20 @@ export interface Route {
contentType?: string; contentType?: string;
/** /**
* Optional response body. * Response headers. Header values will be converted to a string.
*/ */
body?: string|Buffer; headers?: { [key: string]: string; };
/** /**
* Optional file path to respond with. The content type will be inferred from file extension. If `path` is a relative path, * File path to respond with. The content type will be inferred from file extension. If `path` is a relative path, then it
* then it is resolved relative to the current working directory. * is resolved relative to the current working directory.
*/ */
path?: string; path?: string;
/**
* Response status code, defaults to `200`.
*/
status?: number;
}): Promise<void>; }): Promise<void>;
/** /**