doc: further align docs w/ playwright.dev (2) (#4871)

This commit is contained in:
Pavel Feldman 2021-01-04 13:50:29 -08:00 committed by GitHub
parent 3ff81fe172
commit 31ffeb32e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 139 additions and 137 deletions

2
.gitignore vendored
View file

@ -14,7 +14,7 @@ yarn.lock
lib/ lib/
jest-report.json jest-report.json
drivers/ drivers/
/docs/api.json
.android-sdk/ .android-sdk/
.gradle/ .gradle/
nohup.out nohup.out
api.json

View file

@ -38,7 +38,7 @@ Playwright is a library to automate [Chromium](https://www.chromium.org/Home), [
- [Page object models](./pom.md) - [Page object models](./pom.md)
1. Integrations 1. Integrations
- [Test runners](./test-runners.md) - [Test runners](./test-runners.md)
- [Docker](././docker.md) - [Docker](./docker.md)
- [Continuous integration](./ci.md) - [Continuous integration](./ci.md)
1. Reference 1. Reference
- [API Reference](./api/class-playwright.md) - [API Reference](./api/class-playwright.md)

View file

@ -31,8 +31,8 @@ await context.close();
- [browserContext.clearPermissions()](api/class-browsercontext.md#browsercontextclearpermissions) - [browserContext.clearPermissions()](api/class-browsercontext.md#browsercontextclearpermissions)
- [browserContext.close()](api/class-browsercontext.md#browsercontextclose) - [browserContext.close()](api/class-browsercontext.md#browsercontextclose)
- [browserContext.cookies([urls])](api/class-browsercontext.md#browsercontextcookiesurls) - [browserContext.cookies([urls])](api/class-browsercontext.md#browsercontextcookiesurls)
- [browserContext.exposeBinding(name, playwrightBinding[, options])](api/class-browsercontext.md#browsercontextexposebindingname-playwrightbinding-options) - [browserContext.exposeBinding(name, callback[, options])](api/class-browsercontext.md#browsercontextexposebindingname-callback-options)
- [browserContext.exposeFunction(name, playwrightFunction)](api/class-browsercontext.md#browsercontextexposefunctionname-playwrightfunction) - [browserContext.exposeFunction(name, callback)](api/class-browsercontext.md#browsercontextexposefunctionname-callback)
- [browserContext.grantPermissions(permissions[, options])](api/class-browsercontext.md#browsercontextgrantpermissionspermissions-options) - [browserContext.grantPermissions(permissions[, options])](api/class-browsercontext.md#browsercontextgrantpermissionspermissions-options)
- [browserContext.newPage()](api/class-browsercontext.md#browsercontextnewpage) - [browserContext.newPage()](api/class-browsercontext.md#browsercontextnewpage)
- [browserContext.pages()](api/class-browsercontext.md#browsercontextpages) - [browserContext.pages()](api/class-browsercontext.md#browsercontextpages)
@ -92,7 +92,7 @@ await browserContext.addCookies([cookieObject1, cookieObject2]);
## browserContext.addInitScript(script[, arg]) ## browserContext.addInitScript(script[, arg])
- `script` <[function]|[string]|[Object]> Script to be evaluated in all pages in the browser context. - `script` <[function]|[string]|[Object]> Script to be evaluated in all pages in the browser context.
- `path` <[string]> Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to the current working directory. Optional. - `path` <[path]> Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to the current working directory. Optional.
- `content` <[string]> Raw script content. Optional. - `content` <[string]> Raw script content. Optional.
- `arg` <[Serializable]> Optional argument to pass to `script` (only supported when passing a function). - `arg` <[Serializable]> Optional argument to pass to `script` (only supported when passing a function).
- returns: <[Promise]> - returns: <[Promise]>
@ -162,18 +162,18 @@ Closes the browser context. All the pages that belong to the browser context wil
If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs are returned. If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs are returned.
## browserContext.exposeBinding(name, playwrightBinding[, options]) ## browserContext.exposeBinding(name, callback[, options])
- `name` <[string]> Name of the function on the window object. - `name` <[string]> Name of the function on the window object.
- `playwrightBinding` <[function]> Callback function that will be called in the Playwright's context. - `callback` <[function]> Callback function that will be called in the Playwright's context.
- `options` <[Object]> - `options` <[Object]>
- `handle` <[boolean]> Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument is supported. When passing by value, multiple arguments are supported. - `handle` <[boolean]> Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument is supported. When passing by value, multiple arguments are supported.
- returns: <[Promise]> - returns: <[Promise]>
The method adds a function called `name` on the `window` object of every frame in every page in the context. When called, the function executes `playwrightBinding` and returns a [Promise] which resolves to the return value of `playwrightBinding`. If the `playwrightBinding` returns a [Promise], it will be awaited. The method adds a function called `name` on the `window` object of every frame in every page in the context. When called, the function executes `callback` and returns a [Promise] which resolves to the return value of `callback`. If the `callback` returns a [Promise], it will be awaited.
The first argument of the `playwrightBinding` function contains information about the caller: `{ browserContext: BrowserContext, page: Page, frame: Frame }`. The first argument of the `callback` function contains information about the caller: `{ browserContext: BrowserContext, page: Page, frame: Frame }`.
See [page.exposeBinding(name, playwrightBinding[, options])](api/class-page.md#pageexposebindingname-playwrightbinding-options) for page-only version. See [page.exposeBinding(name, callback[, options])](api/class-page.md#pageexposebindingname-callback-options) for page-only version.
An example of exposing page URL to all frames in all pages in the context: An example of exposing page URL to all frames in all pages in the context:
@ -213,16 +213,16 @@ await page.setContent(`
`); `);
``` ```
## browserContext.exposeFunction(name, playwrightFunction) ## browserContext.exposeFunction(name, callback)
- `name` <[string]> Name of the function on the window object. - `name` <[string]> Name of the function on the window object.
- `playwrightFunction` <[function]> Callback function that will be called in the Playwright's context. - `callback` <[function]> Callback function that will be called in the Playwright's context.
- returns: <[Promise]> - returns: <[Promise]>
The method adds a function called `name` on the `window` object of every frame in every page in the context. When called, the function executes `playwrightFunction` and returns a [Promise] which resolves to the return value of `playwrightFunction`. The method adds a function called `name` on the `window` object of every frame in every page in the context. When called, the function executes `callback` and returns a [Promise] which resolves to the return value of `callback`.
If the `playwrightFunction` returns a [Promise], it will be awaited. If the `callback` returns a [Promise], it will be awaited.
See [page.exposeFunction(name, playwrightFunction)](api/class-page.md#pageexposefunctionname-playwrightfunction) for page-only version. See [page.exposeFunction(name, callback)](api/class-page.md#pageexposefunctionname-callback) for page-only version.
An example of adding an `md5` function to all pages in the context: An example of adding an `md5` function to all pages in the context:
@ -372,7 +372,7 @@ Provide credentials for [HTTP authentication](https://developer.mozilla.org/en-U
## browserContext.storageState([options]) ## browserContext.storageState([options])
- `options` <[Object]> - `options` <[Object]>
- `path` <[string]> The file path to save the storage state to. If `path` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). If no path is provided, storage state is still returned, but won't be saved to the disk. - `path` <[path]> The file path to save the storage state to. If `path` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). If no path is provided, storage state is still returned, but won't be saved to the disk.
- returns: <[Promise]<[Object]>> - returns: <[Promise]<[Object]>>
- `cookies` <[Array]<[Object]>> - `cookies` <[Array]<[Object]>>
- `name` <[string]> - `name` <[string]>

View file

@ -46,9 +46,9 @@ A path where Playwright expects to find a bundled browser executable.
- `args` <[Array]<[string]>> Additional arguments to pass to the browser instance. The list of Chromium flags can be found [here](http://peter.sh/experiments/chromium-command-line-switches/). - `args` <[Array]<[string]>> Additional arguments to pass to the browser instance. The list of Chromium flags can be found [here](http://peter.sh/experiments/chromium-command-line-switches/).
- `chromiumSandbox` <[boolean]> Enable Chromium sandboxing. Defaults to `false`. - `chromiumSandbox` <[boolean]> Enable Chromium sandboxing. Defaults to `false`.
- `devtools` <[boolean]> **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the `headless` option will be set `false`. - `devtools` <[boolean]> **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the `headless` option will be set `false`.
- `downloadsPath` <[string]> If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed. - `downloadsPath` <[path]> If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed.
- `env` <[Object]<[string], [string]|[number]|[boolean]>> Specify environment variables that will be visible to the browser. Defaults to `process.env`. - `env` <[Object]<[string], [string]|[number]|[boolean]>> Specify environment variables that will be visible to the browser. Defaults to `process.env`.
- `executablePath` <[string]> Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is resolved relative to the current working directory. Note that Playwright only works with the bundled Chromium, Firefox or WebKit, use at your own risk. - `executablePath` <[path]> Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is resolved relative to the current working directory. Note that Playwright only works with the bundled Chromium, Firefox or WebKit, use at your own risk.
- `firefoxUserPrefs` <[Object]<[string], [string]|[number]|[boolean]>> Firefox user preferences. Learn more about the Firefox user preferences at [`about:config`](https://support.mozilla.org/en-US/kb/about-config-editor-firefox). - `firefoxUserPrefs` <[Object]<[string], [string]|[number]|[boolean]>> Firefox user preferences. Learn more about the Firefox user preferences at [`about:config`](https://support.mozilla.org/en-US/kb/about-config-editor-firefox).
- `handleSIGHUP` <[boolean]> Close the browser process on SIGHUP. Defaults to `true`. - `handleSIGHUP` <[boolean]> Close the browser process on SIGHUP. Defaults to `true`.
- `handleSIGINT` <[boolean]> Close the browser process on Ctrl-C. Defaults to `true`. - `handleSIGINT` <[boolean]> Close the browser process on Ctrl-C. Defaults to `true`.
@ -84,7 +84,7 @@ const browser = await chromium.launch({ // Or 'firefox' or 'webkit'.
> See [`this article`](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for a description of the differences between Chromium and Chrome. [`This article`](https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md) describes some differences for Linux users. > See [`this article`](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for a description of the differences between Chromium and Chrome. [`This article`](https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md) describes some differences for Linux users.
## browserType.launchPersistentContext(userDataDir[, options]) ## browserType.launchPersistentContext(userDataDir[, options])
- `userDataDir` <[string]> Path to a User Data Directory, which stores browser session data like cookies and local storage. More details for [Chromium](https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md) and [Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options#User_Profile). - `userDataDir` <[path]> Path to a User Data Directory, which stores browser session data like cookies and local storage. More details for [Chromium](https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md) and [Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options#User_Profile).
- `options` <[Object]> - `options` <[Object]>
- `acceptDownloads` <[boolean]> Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled. - `acceptDownloads` <[boolean]> Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled.
- `args` <[Array]<[string]>> Additional arguments to pass to the browser instance. The list of Chromium flags can be found [here](http://peter.sh/experiments/chromium-command-line-switches/). - `args` <[Array]<[string]>> Additional arguments to pass to the browser instance. The list of Chromium flags can be found [here](http://peter.sh/experiments/chromium-command-line-switches/).
@ -93,9 +93,9 @@ const browser = await chromium.launch({ // Or 'firefox' or 'webkit'.
- `colorScheme` <"light"|"dark"|"no-preference"> Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See [page.emulateMedia(params)](api/class-page.md#pageemulatemediaparams) for more details. Defaults to '`light`'. - `colorScheme` <"light"|"dark"|"no-preference"> Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See [page.emulateMedia(params)](api/class-page.md#pageemulatemediaparams) for more details. Defaults to '`light`'.
- `deviceScaleFactor` <[number]> Specify device scale factor (can be thought of as dpr). Defaults to `1`. - `deviceScaleFactor` <[number]> Specify device scale factor (can be thought of as dpr). Defaults to `1`.
- `devtools` <[boolean]> **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the `headless` option will be set `false`. - `devtools` <[boolean]> **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the `headless` option will be set `false`.
- `downloadsPath` <[string]> If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed. - `downloadsPath` <[path]> If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed.
- `env` <[Object]<[string], [string]|[number]|[boolean]>> Specify environment variables that will be visible to the browser. Defaults to `process.env`. - `env` <[Object]<[string], [string]|[number]|[boolean]>> Specify environment variables that will be visible to the browser. Defaults to `process.env`.
- `executablePath` <[string]> Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is resolved relative to the current working directory. **BEWARE**: Playwright is only guaranteed to work with the bundled Chromium, Firefox or WebKit, use at your own risk. - `executablePath` <[path]> Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is resolved relative to the current working directory. **BEWARE**: Playwright is only guaranteed to work with the bundled Chromium, Firefox or WebKit, use at your own risk.
- `extraHTTPHeaders` <[Object]<[string], [string]>> An object containing additional HTTP headers to be sent with every request. All header values must be strings. - `extraHTTPHeaders` <[Object]<[string], [string]>> An object containing additional HTTP headers to be sent with every request. All header values must be strings.
- `geolocation` <[Object]> - `geolocation` <[Object]>
- `latitude` <[number]> Latitude between -90 and 90. - `latitude` <[number]> Latitude between -90 and 90.
@ -152,9 +152,9 @@ Launches browser that uses persistent storage located at `userDataDir` and retur
- `args` <[Array]<[string]>> Additional arguments to pass to the browser instance. The list of Chromium flags can be found [here](http://peter.sh/experiments/chromium-command-line-switches/). - `args` <[Array]<[string]>> Additional arguments to pass to the browser instance. The list of Chromium flags can be found [here](http://peter.sh/experiments/chromium-command-line-switches/).
- `chromiumSandbox` <[boolean]> Enable Chromium sandboxing. Defaults to `true`. - `chromiumSandbox` <[boolean]> Enable Chromium sandboxing. Defaults to `true`.
- `devtools` <[boolean]> **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the `headless` option will be set `false`. - `devtools` <[boolean]> **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the `headless` option will be set `false`.
- `downloadsPath` <[string]> If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed. - `downloadsPath` <[path]> If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed.
- `env` <[Object]<[string], [string]|[number]|[boolean]>> Specify environment variables that will be visible to the browser. Defaults to `process.env`. - `env` <[Object]<[string], [string]|[number]|[boolean]>> Specify environment variables that will be visible to the browser. Defaults to `process.env`.
- `executablePath` <[string]> Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is resolved relative to the current working directory. **BEWARE**: Playwright is only guaranteed to work with the bundled Chromium, Firefox or WebKit, use at your own risk. - `executablePath` <[path]> Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is resolved relative to the current working directory. **BEWARE**: Playwright is only guaranteed to work with the bundled Chromium, Firefox or WebKit, use at your own risk.
- `firefoxUserPrefs` <[Object]<[string], [string]|[number]|[boolean]>> Firefox user preferences. Learn more about the Firefox user preferences at [`about:config`](https://support.mozilla.org/en-US/kb/about-config-editor-firefox). - `firefoxUserPrefs` <[Object]<[string], [string]|[number]|[boolean]>> Firefox user preferences. Learn more about the Firefox user preferences at [`about:config`](https://support.mozilla.org/en-US/kb/about-config-editor-firefox).
- `handleSIGHUP` <[boolean]> Close the browser process on SIGHUP. Defaults to `true`. - `handleSIGHUP` <[boolean]> Close the browser process on SIGHUP. Defaults to `true`.
- `handleSIGINT` <[boolean]> Close the browser process on Ctrl-C. Defaults to `true`. - `handleSIGINT` <[boolean]> Close the browser process on Ctrl-C. Defaults to `true`.

View file

@ -34,7 +34,7 @@ Returns the newly created browser session.
- `page` <[Page]> Optional, if specified, tracing includes screenshots of the given page. - `page` <[Page]> Optional, if specified, tracing includes screenshots of the given page.
- `options` <[Object]> - `options` <[Object]>
- `categories` <[Array]<[string]>> specify custom categories to use instead of default. - `categories` <[Array]<[string]>> specify custom categories to use instead of default.
- `path` <[string]> A path to write the trace file to. - `path` <[path]> A path to write the trace file to.
- `screenshots` <[boolean]> captures screenshots in the trace. - `screenshots` <[boolean]> captures screenshots in the trace.
- returns: <[Promise]> - returns: <[Promise]>

View file

@ -26,8 +26,8 @@ const backgroundPage = await context.waitForEvent('backgroundpage');
- [browserContext.clearPermissions()](api/class-browsercontext.md#browsercontextclearpermissions) - [browserContext.clearPermissions()](api/class-browsercontext.md#browsercontextclearpermissions)
- [browserContext.close()](api/class-browsercontext.md#browsercontextclose) - [browserContext.close()](api/class-browsercontext.md#browsercontextclose)
- [browserContext.cookies([urls])](api/class-browsercontext.md#browsercontextcookiesurls) - [browserContext.cookies([urls])](api/class-browsercontext.md#browsercontextcookiesurls)
- [browserContext.exposeBinding(name, playwrightBinding[, options])](api/class-browsercontext.md#browsercontextexposebindingname-playwrightbinding-options) - [browserContext.exposeBinding(name, callback[, options])](api/class-browsercontext.md#browsercontextexposebindingname-callback-options)
- [browserContext.exposeFunction(name, playwrightFunction)](api/class-browsercontext.md#browsercontextexposefunctionname-playwrightfunction) - [browserContext.exposeFunction(name, callback)](api/class-browsercontext.md#browsercontextexposefunctionname-callback)
- [browserContext.grantPermissions(permissions[, options])](api/class-browsercontext.md#browsercontextgrantpermissionspermissions-options) - [browserContext.grantPermissions(permissions[, options])](api/class-browsercontext.md#browsercontextgrantpermissionspermissions-options)
- [browserContext.newPage()](api/class-browsercontext.md#browsercontextnewpage) - [browserContext.newPage()](api/class-browsercontext.md#browsercontextnewpage)
- [browserContext.pages()](api/class-browsercontext.md#browsercontextpages) - [browserContext.pages()](api/class-browsercontext.md#browsercontextpages)

View file

@ -52,7 +52,7 @@ Returns download error if any.
Returns path to the downloaded file in case of successful download. Returns path to the downloaded file in case of successful download.
## download.saveAs(path) ## download.saveAs(path)
- `path` <[string]> Path where the download should be saved. - `path` <[path]> Path where the download should be saved.
- returns: <[Promise]> - returns: <[Promise]>
Saves the download to a user-specified path. Saves the download to a user-specified path.

View file

@ -323,7 +323,7 @@ Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported a
## elementHandle.screenshot([options]) ## elementHandle.screenshot([options])
- `options` <[Object]> - `options` <[Object]>
- `omitBackground` <[boolean]> Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images. Defaults to `false`. - `omitBackground` <[boolean]> Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images. Defaults to `false`.
- `path` <[string]> The file path to save the image to. The screenshot type will be inferred from file extension. If `path` is a relative path, then it is resolved relative to the current working directory. If no path is provided, the image won't be saved to the disk. - `path` <[path]> The file path to save the image to. The screenshot type will be inferred from file extension. If `path` is a relative path, then it is resolved relative to the current working directory. If no path is provided, the image won't be saved to the disk.
- `quality` <[number]> The quality of the image, between 0-100. Not applicable to `png` images. - `quality` <[number]> The quality of the image, between 0-100. Not applicable to `png` images.
- `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](api/class-browsercontext.md#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](api/class-page.md#pagesetdefaulttimeouttimeout) methods. - `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](api/class-browsercontext.md#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](api/class-page.md#pagesetdefaulttimeouttimeout) methods.
- `type` <"png"|"jpeg"> Specify screenshot type, defaults to `png`. - `type` <"png"|"jpeg"> Specify screenshot type, defaults to `png`.

View file

@ -140,7 +140,7 @@ const divsCounts = await frame.$$eval('div', (divs, min) => divs.length >= min,
## frame.addScriptTag(params) ## frame.addScriptTag(params)
- `params` <[Object]> - `params` <[Object]>
- `url` <[string]> URL of a script to be added. Optional. - `url` <[string]> URL of a script to be added. Optional.
- `path` <[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` <[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.
- `content` <[string]> Raw JavaScript content to be injected into frame. Optional. - `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. - `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.
- returns: <[Promise]<[ElementHandle]>> - returns: <[Promise]<[ElementHandle]>>
@ -152,7 +152,7 @@ Adds a `<script>` tag into the page with the desired url or content.
## frame.addStyleTag(params) ## frame.addStyleTag(params)
- `params` <[Object]> - `params` <[Object]>
- `url` <[string]> URL of the `<link>` tag. Optional. - `url` <[string]> URL of the `<link>` tag. Optional.
- `path` <[string]> 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. - `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.
- `content` <[string]> Raw CSS content to be injected into frame. Optional. - `content` <[string]> Raw CSS content to be injected into frame. Optional.
- returns: <[Promise]<[ElementHandle]>> - returns: <[Promise]<[ElementHandle]>>
@ -664,7 +664,7 @@ await frame.waitForLoadState(); // Waits for 'load' state by default.
## frame.waitForNavigation([options]) ## frame.waitForNavigation([options])
- `options` <[Object]> - `options` <[Object]>
- `timeout` <[number]> Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](api/class-browsercontext.md#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](api/class-browsercontext.md#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](api/class-page.md#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](api/class-page.md#pagesetdefaulttimeouttimeout) methods. - `timeout` <[number]> Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](api/class-browsercontext.md#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](api/class-browsercontext.md#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](api/class-page.md#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](api/class-page.md#pagesetdefaulttimeouttimeout) methods.
- `url` <[string]|[RegExp]|[Function]> URL string, URL regex pattern or predicate receiving [URL] to match while waiting for the navigation. - `url` <[string]|[RegExp]|[function]\([URL]\):[boolean]> URL string, URL regex pattern or predicate receiving [URL] to match while waiting for the navigation.
- `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider operation succeeded, defaults to `load`. Events can be either: - `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider operation succeeded, defaults to `load`. Events can be either:
* `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. * `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
* `'load'` - consider operation to be finished when the `load` event is fired. * `'load'` - consider operation to be finished when the `load` event is fired.

View file

@ -81,8 +81,8 @@ page.removeListener('request', logRequest);
- [page.emulateMedia(params)](api/class-page.md#pageemulatemediaparams) - [page.emulateMedia(params)](api/class-page.md#pageemulatemediaparams)
- [page.evaluate(pageFunction[, arg])](api/class-page.md#pageevaluatepagefunction-arg) - [page.evaluate(pageFunction[, arg])](api/class-page.md#pageevaluatepagefunction-arg)
- [page.evaluateHandle(pageFunction[, arg])](api/class-page.md#pageevaluatehandlepagefunction-arg) - [page.evaluateHandle(pageFunction[, arg])](api/class-page.md#pageevaluatehandlepagefunction-arg)
- [page.exposeBinding(name, playwrightBinding[, options])](api/class-page.md#pageexposebindingname-playwrightbinding-options) - [page.exposeBinding(name, callback[, options])](api/class-page.md#pageexposebindingname-callback-options)
- [page.exposeFunction(name, playwrightFunction)](api/class-page.md#pageexposefunctionname-playwrightfunction) - [page.exposeFunction(name, callback)](api/class-page.md#pageexposefunctionname-callback)
- [page.fill(selector, value[, options])](api/class-page.md#pagefillselector-value-options) - [page.fill(selector, value[, options])](api/class-page.md#pagefillselector-value-options)
- [page.focus(selector[, options])](api/class-page.md#pagefocusselector-options) - [page.focus(selector[, options])](api/class-page.md#pagefocusselector-options)
- [page.frame(frameSelector)](api/class-page.md#pageframeframeselector) - [page.frame(frameSelector)](api/class-page.md#pageframeframeselector)
@ -338,7 +338,7 @@ const divsCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 1
## page.addInitScript(script[, arg]) ## page.addInitScript(script[, arg])
- `script` <[function]|[string]|[Object]> Script to be evaluated in the page. - `script` <[function]|[string]|[Object]> Script to be evaluated in the page.
- `path` <[string]> Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to the current working directory. Optional. - `path` <[path]> Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to the current working directory. Optional.
- `content` <[string]> Raw script content. Optional. - `content` <[string]> Raw script content. Optional.
- `arg` <[Serializable]> Optional argument to pass to `script` (only supported when passing a function). - `arg` <[Serializable]> Optional argument to pass to `script` (only supported when passing a function).
- returns: <[Promise]> - returns: <[Promise]>
@ -365,7 +365,7 @@ await page.addInitScript(preloadFile);
## page.addScriptTag(params) ## page.addScriptTag(params)
- `params` <[Object]> - `params` <[Object]>
- `url` <[string]> URL of a script to be added. Optional. - `url` <[string]> URL of a script to be added. Optional.
- `path` <[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` <[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.
- `content` <[string]> Raw JavaScript content to be injected into frame. Optional. - `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. - `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.
- returns: <[Promise]<[ElementHandle]>> - returns: <[Promise]<[ElementHandle]>>
@ -377,7 +377,7 @@ Shortcut for main frame's [frame.addScriptTag(params)](api/class-frame.md#framea
## page.addStyleTag(params) ## page.addStyleTag(params)
- `params` <[Object]> - `params` <[Object]>
- `url` <[string]> URL of the `<link>` tag. Optional. - `url` <[string]> URL of the `<link>` tag. Optional.
- `path` <[string]> 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. - `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.
- `content` <[string]> Raw CSS content to be injected into frame. Optional. - `content` <[string]> Raw CSS content to be injected into frame. Optional.
- returns: <[Promise]<[ElementHandle]>> - returns: <[Promise]<[ElementHandle]>>
@ -623,18 +623,18 @@ console.log(await resultHandle.jsonValue());
await resultHandle.dispose(); await resultHandle.dispose();
``` ```
## page.exposeBinding(name, playwrightBinding[, options]) ## page.exposeBinding(name, callback[, options])
- `name` <[string]> Name of the function on the window object. - `name` <[string]> Name of the function on the window object.
- `playwrightBinding` <[function]> Callback function that will be called in the Playwright's context. - `callback` <[function]> Callback function that will be called in the Playwright's context.
- `options` <[Object]> - `options` <[Object]>
- `handle` <[boolean]> Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument is supported. When passing by value, multiple arguments are supported. - `handle` <[boolean]> Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument is supported. When passing by value, multiple arguments are supported.
- returns: <[Promise]> - returns: <[Promise]>
The method adds a function called `name` on the `window` object of every frame in this page. When called, the function executes `playwrightBinding` and returns a [Promise] which resolves to the return value of `playwrightBinding`. If the `playwrightBinding` returns a [Promise], it will be awaited. The method adds a function called `name` on the `window` object of every frame in this page. When called, the function executes `callback` and returns a [Promise] which resolves to the return value of `callback`. If the `callback` returns a [Promise], it will be awaited.
The first argument of the `playwrightBinding` function contains information about the caller: `{ browserContext: BrowserContext, page: Page, frame: Frame }`. The first argument of the `callback` function contains information about the caller: `{ browserContext: BrowserContext, page: Page, frame: Frame }`.
See [browserContext.exposeBinding(name, playwrightBinding[, options])](api/class-browsercontext.md#browsercontextexposebindingname-playwrightbinding-options) for the context-wide version. See [browserContext.exposeBinding(name, callback[, options])](api/class-browsercontext.md#browsercontextexposebindingname-callback-options) for the context-wide version.
> **NOTE** Functions installed via `page.exposeBinding` survive navigations. > **NOTE** Functions installed via `page.exposeBinding` survive navigations.
@ -676,16 +676,16 @@ await page.setContent(`
`); `);
``` ```
## page.exposeFunction(name, playwrightFunction) ## page.exposeFunction(name, callback)
- `name` <[string]> Name of the function on the window object - `name` <[string]> Name of the function on the window object
- `playwrightFunction` <[function]> Callback function which will be called in Playwright's context. - `callback` <[function]> Callback function which will be called in Playwright's context.
- returns: <[Promise]> - returns: <[Promise]>
The method adds a function called `name` on the `window` object of every frame in the page. When called, the function executes `playwrightFunction` and returns a [Promise] which resolves to the return value of `playwrightFunction`. The method adds a function called `name` on the `window` object of every frame in the page. When called, the function executes `callback` and returns a [Promise] which resolves to the return value of `callback`.
If the `playwrightFunction` returns a [Promise], it will be awaited. If the `callback` returns a [Promise], it will be awaited.
See [browserContext.exposeFunction(name, playwrightFunction)](api/class-browsercontext.md#browsercontextexposefunctionname-playwrightfunction) for context-wide exposed function. See [browserContext.exposeFunction(name, callback)](api/class-browsercontext.md#browsercontextexposefunctionname-callback) for context-wide exposed function.
> **NOTE** Functions installed via `page.exposeFunction` survive navigations. > **NOTE** Functions installed via `page.exposeFunction` survive navigations.
@ -768,7 +768,7 @@ Shortcut for main frame's [frame.focus(selector[, options])](api/class-frame.md#
## page.frame(frameSelector) ## page.frame(frameSelector)
- `frameSelector` <[string]|[Object]> Frame name or other frame lookup options. - `frameSelector` <[string]|[Object]> Frame name or other frame lookup options.
- `name` <[string]> Frame name specified in the `iframe`'s `name` attribute. Optional. - `name` <[string]> Frame name specified in the `iframe`'s `name` attribute. Optional.
- `url` <[string]|[RegExp]|[Function]> A glob pattern, regex pattern or predicate receiving frame's `url` as a [URL] object. Optional. - `url` <[string]|[RegExp]|[function]\([URL]\):[boolean]> A glob pattern, regex pattern or predicate receiving frame's `url` as a [URL] object. Optional.
- returns: <[null]|[Frame]> - returns: <[null]|[Frame]>
Returns frame matching the specified criteria. Either `name` or `url` must be specified. Returns frame matching the specified criteria. Either `name` or `url` must be specified.
@ -926,7 +926,7 @@ Returns the opener for popup pages and `null` for others. If the opener has been
- `bottom` <[string]|[number]> Bottom margin, accepts values labeled with units. Defaults to `0`. - `bottom` <[string]|[number]> Bottom margin, accepts values labeled with units. Defaults to `0`.
- `left` <[string]|[number]> Left margin, accepts values labeled with units. Defaults to `0`. - `left` <[string]|[number]> Left margin, accepts values labeled with units. Defaults to `0`.
- `pageRanges` <[string]> Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages. - `pageRanges` <[string]> Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
- `path` <[string]> The file path to save the PDF to. If `path` is a relative path, then it is resolved relative to the current working directory. If no path is provided, the PDF won't be saved to the disk. - `path` <[path]> The file path to save the PDF to. If `path` is a relative path, then it is resolved relative to the current working directory. If no path is provided, the PDF won't be saved to the disk.
- `preferCSSPageSize` <[boolean]> Give any CSS `@page` size declared in the page priority over what is declared in `width` and `height` or `format` options. Defaults to `false`, which will scale the content to fit the paper size. - `preferCSSPageSize` <[boolean]> Give any CSS `@page` size declared in the page priority over what is declared in `width` and `height` or `format` options. Defaults to `false`, which will scale the content to fit the paper size.
- `printBackground` <[boolean]> Print background graphics. Defaults to `false`. - `printBackground` <[boolean]> Print background graphics. Defaults to `false`.
- `scale` <[number]> Scale of the webpage rendering. Defaults to `1`. Scale amount must be between 0.1 and 2. - `scale` <[number]> Scale of the webpage rendering. Defaults to `1`. Scale amount must be between 0.1 and 2.
@ -1065,7 +1065,7 @@ Page routes take precedence over browser context routes (set up with [browserCon
- `height` <[number]> height of clipping area - `height` <[number]> height of clipping area
- `fullPage` <[boolean]> When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to `false`. - `fullPage` <[boolean]> When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to `false`.
- `omitBackground` <[boolean]> Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images. Defaults to `false`. - `omitBackground` <[boolean]> Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images. Defaults to `false`.
- `path` <[string]> The file path to save the image to. The screenshot type will be inferred from file extension. If `path` is a relative path, then it is resolved relative to the current working directory. If no path is provided, the image won't be saved to the disk. - `path` <[path]> The file path to save the image to. The screenshot type will be inferred from file extension. If `path` is a relative path, then it is resolved relative to the current working directory. If no path is provided, the image won't be saved to the disk.
- `quality` <[number]> The quality of the image, between 0-100. Not applicable to `png` images. - `quality` <[number]> The quality of the image, between 0-100. Not applicable to `png` images.
- `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](api/class-browsercontext.md#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](api/class-page.md#pagesetdefaulttimeouttimeout) methods. - `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](api/class-browsercontext.md#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](api/class-page.md#pagesetdefaulttimeouttimeout) methods.
- `type` <"png"|"jpeg"> Specify screenshot type, defaults to `png`. - `type` <"png"|"jpeg"> Specify screenshot type, defaults to `png`.
@ -1357,7 +1357,7 @@ Shortcut for main frame's [frame.waitForLoadState([state, options])](api/class-f
## page.waitForNavigation([options]) ## page.waitForNavigation([options])
- `options` <[Object]> - `options` <[Object]>
- `timeout` <[number]> Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](api/class-browsercontext.md#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](api/class-browsercontext.md#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](api/class-page.md#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](api/class-page.md#pagesetdefaulttimeouttimeout) methods. - `timeout` <[number]> Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultNavigationTimeout(timeout)](api/class-browsercontext.md#browsercontextsetdefaultnavigationtimeouttimeout), [browserContext.setDefaultTimeout(timeout)](api/class-browsercontext.md#browsercontextsetdefaulttimeouttimeout), [page.setDefaultNavigationTimeout(timeout)](api/class-page.md#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](api/class-page.md#pagesetdefaulttimeouttimeout) methods.
- `url` <[string]|[RegExp]|[Function]> A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. - `url` <[string]|[RegExp]|[function]\([URL]\):[boolean]> A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation.
- `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider operation succeeded, defaults to `load`. Events can be either: - `waitUntil` <"load"|"domcontentloaded"|"networkidle"> When to consider operation succeeded, defaults to `load`. Events can be either:
* `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. * `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
* `'load'` - consider operation to be finished when the `load` event is fired. * `'load'` - consider operation to be finished when the `load` event is fired.
@ -1380,7 +1380,7 @@ const [response] = await Promise.all([
Shortcut for main frame's [frame.waitForNavigation([options])](api/class-frame.md#framewaitfornavigationoptions). Shortcut for main frame's [frame.waitForNavigation([options])](api/class-frame.md#framewaitfornavigationoptions).
## page.waitForRequest(urlOrPredicate[, options]) ## page.waitForRequest(urlOrPredicate[, options])
- `urlOrPredicate` <[string]|[RegExp]|[Function]> Request URL string, regex or predicate receiving [Request] object. - `urlOrPredicate` <[string]|[RegExp]|[function]\([Request]\):[boolean]> Request URL string, regex or predicate receiving [Request] object.
- `options` <[Object]> - `options` <[Object]>
- `timeout` <[number]> Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can be changed by using the [page.setDefaultTimeout(timeout)](api/class-page.md#pagesetdefaulttimeouttimeout) method. - `timeout` <[number]> Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can be changed by using the [page.setDefaultTimeout(timeout)](api/class-page.md#pagesetdefaulttimeouttimeout) method.
- returns: <[Promise]<[Request]>> - returns: <[Promise]<[Request]>>

View file

@ -60,7 +60,7 @@ await page.route('**/*', (route, request) => {
- `headers` <[Object]<[string], [string]>> Optional response headers. Header values will be converted to a string. - `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. - `contentType` <[string]> If set, equals to setting `Content-Type` response header.
- `body` <[string]|[Buffer]> Optional response body. - `body` <[string]|[Buffer]> Optional response body.
- `path` <[string]> 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. - `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.
- returns: <[Promise]> - returns: <[Promise]>
Fulfills route's request with given response. Fulfills route's request with given response.

View file

@ -12,7 +12,7 @@ Selectors can be used to install custom selector engines. See [Working with sele
## selectors.register(name, script[, options]) ## selectors.register(name, script[, options])
- `name` <[string]> Name that is used in selectors as a prefix, e.g. `{name: 'foo'}` enables `foo=myselectorbody` selectors. May only contain `[a-zA-Z0-9_]` characters. - `name` <[string]> Name that is used in selectors as a prefix, e.g. `{name: 'foo'}` enables `foo=myselectorbody` selectors. May only contain `[a-zA-Z0-9_]` characters.
- `script` <[function]|[string]|[Object]> Script that evaluates to a selector engine instance. - `script` <[function]|[string]|[Object]> Script that evaluates to a selector engine instance.
- `path` <[string]> Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to the current working directory. Optional. - `path` <[path]> Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to the current working directory. Optional.
- `content` <[string]> Raw script content. Optional. - `content` <[string]> Raw script content. Optional.
- `options` <[Object]> - `options` <[Object]>
- `contentScript` <[boolean]> Whether to run this selector engine in isolated JavaScript environment. This environment has access to the same DOM, but not any JavaScript objects from the frame's scripts. Defaults to `false`. Note that running as a content script is not guaranteed when this engine is used together with other registered engines. - `contentScript` <[boolean]> Whether to run this selector engine in isolated JavaScript environment. This environment has access to the same DOM, but not any JavaScript objects from the frame's scripts. Defaults to `false`. Note that running as a content script is not guaranteed when this engine is used together with other registered engines.

View file

@ -40,7 +40,7 @@ Playwright is a library to automate [Chromium](https://www.chromium.org/Home), [
- [Page object models](./pom.md) - [Page object models](./pom.md)
1. Integrations 1. Integrations
- [Test runners](./test-runners.md) - [Test runners](./test-runners.md)
- [Docker](././docker.md) - [Docker](./docker.md)
- [Continuous integration](./ci.md) - [Continuous integration](./ci.md)
1. Reference 1. Reference
- [API Reference](./api/class-playwright.md) - [API Reference](./api/class-playwright.md)

View file

@ -275,7 +275,7 @@ await browserContext.addInitScript({
### param: BrowserContext.addInitScript.script ### param: BrowserContext.addInitScript.script
- `script` <[function]|[string]|[Object]> - `script` <[function]|[string]|[Object]>
- `path` <[string]> Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to the current working directory. Optional. - `path` <[path]> Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to the current working directory. Optional.
- `content` <[string]> Raw script content. Optional. - `content` <[string]> Raw script content. Optional.
Script to be evaluated in all pages in the browser context. Script to be evaluated in all pages in the browser context.
@ -333,10 +333,10 @@ Optional list of URLs.
## async method: BrowserContext.exposeBinding ## async method: BrowserContext.exposeBinding
The method adds a function called [`param: name`] on the `window` object of every frame in every page in the context. The method adds a function called [`param: name`] on the `window` object of every frame in every page in the context.
When called, the function executes [`param: playwrightBinding`] and returns a [Promise] which resolves to the return When called, the function executes [`param: callback`] and returns a [Promise] which resolves to the return
value of [`param: playwrightBinding`]. If the [`param: playwrightBinding`] returns a [Promise], it will be awaited. value of [`param: callback`]. If the [`param: callback`] returns a [Promise], it will be awaited.
The first argument of the [`param: playwrightBinding`] function contains information about the caller: `{ The first argument of the [`param: callback`] function contains information about the caller: `{
browserContext: BrowserContext, page: Page, frame: Frame }`. browserContext: BrowserContext, page: Page, frame: Frame }`.
See [`method: Page.exposeBinding`] for page-only version. See [`method: Page.exposeBinding`] for page-only version.
@ -384,8 +384,8 @@ await page.setContent(`
Name of the function on the window object. Name of the function on the window object.
### param: BrowserContext.exposeBinding.playwrightBinding ### param: BrowserContext.exposeBinding.callback
- `playwrightBinding` <[function]> - `callback` <[function]>
Callback function that will be called in the Playwright's context. Callback function that will be called in the Playwright's context.
@ -398,10 +398,10 @@ supported. When passing by value, multiple arguments are supported.
## async method: BrowserContext.exposeFunction ## async method: BrowserContext.exposeFunction
The method adds a function called [`param: name`] on the `window` object of every frame in every page in the context. The method adds a function called [`param: name`] on the `window` object of every frame in every page in the context.
When called, the function executes [`param: playwrightFunction`] and returns a [Promise] which resolves to the return When called, the function executes [`param: callback`] and returns a [Promise] which resolves to the return
value of [`param: playwrightFunction`]. value of [`param: callback`].
If the [`param: playwrightFunction`] returns a [Promise], it will be awaited. If the [`param: callback`] returns a [Promise], it will be awaited.
See [`method: Page.exposeFunction`] for page-only version. See [`method: Page.exposeFunction`] for page-only version.
@ -434,8 +434,8 @@ const crypto = require('crypto');
Name of the function on the window object. Name of the function on the window object.
### param: BrowserContext.exposeFunction.playwrightFunction ### param: BrowserContext.exposeFunction.callback
- `playwrightFunction` <[function]> - `callback` <[function]>
Callback function that will be called in the Playwright's context. Callback function that will be called in the Playwright's context.
@ -621,7 +621,7 @@ Whether to emulate network being offline for the browser context.
Returns storage state for this browser context, contains current cookies and local storage snapshot. Returns storage state for this browser context, contains current cookies and local storage snapshot.
### option: BrowserContext.storageState.path ### option: BrowserContext.storageState.path
- `path` <[string]> - `path` <[path]>
The file path to save the storage state to. If [`option: path`] is a relative path, then it is resolved relative to The file path to save the storage state to. If [`option: path`] is a relative path, then it is resolved relative to
[current working directory](https://nodejs.org/api/process.html#process_process_cwd). If no path is provided, storage [current working directory](https://nodejs.org/api/process.html#process_process_cwd). If no path is provided, storage
@ -984,7 +984,7 @@ await page.addInitScript(preloadFile);
### param: Page.addInitScript.script ### param: Page.addInitScript.script
- `script` <[function]|[string]|[Object]> - `script` <[function]|[string]|[Object]>
- `path` <[string]> Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to the current working directory. Optional. - `path` <[path]> Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to the current working directory. Optional.
- `content` <[string]> Raw script content. Optional. - `content` <[string]> Raw script content. Optional.
Script to be evaluated in the page. Script to be evaluated in the page.
@ -1005,7 +1005,7 @@ Shortcut for main frame's [`method: Frame.addScriptTag`].
### param: Page.addScriptTag.params ### param: Page.addScriptTag.params
- `params` <[Object]> - `params` <[Object]>
- `url` <[string]> URL of a script to be added. Optional. - `url` <[string]> URL of a script to be added. Optional.
- `path` <[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` <[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.
- `content` <[string]> Raw JavaScript content to be injected into frame. Optional. - `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. - `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.
@ -1020,7 +1020,7 @@ Shortcut for main frame's [`method: Frame.addStyleTag`].
### param: Page.addStyleTag.params ### param: Page.addStyleTag.params
- `params` <[Object]> - `params` <[Object]>
- `url` <[string]> URL of the `<link>` tag. Optional. - `url` <[string]> URL of the `<link>` tag. Optional.
- `path` <[string]> 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. - `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.
- `content` <[string]> Raw CSS content to be injected into frame. Optional. - `content` <[string]> Raw CSS content to be injected into frame. Optional.
## async method: Page.bringToFront ## async method: Page.bringToFront
@ -1317,10 +1317,10 @@ Optional argument to pass to [`param: pageFunction`]
## async method: Page.exposeBinding ## async method: Page.exposeBinding
The method adds a function called [`param: name`] on the `window` object of every frame in this page. When called, the The method adds a function called [`param: name`] on the `window` object of every frame in this page. When called, the
function executes [`param: playwrightBinding`] and returns a [Promise] which resolves to the return value of [`param: function executes [`param: callback`] and returns a [Promise] which resolves to the return value of [`param:
playwrightBinding`]. If the [`param: playwrightBinding`] returns a [Promise], it will be awaited. callback`]. If the [`param: callback`] returns a [Promise], it will be awaited.
The first argument of the [`param: playwrightBinding`] function contains information about the caller: `{ The first argument of the [`param: callback`] function contains information about the caller: `{
browserContext: BrowserContext, page: Page, frame: Frame }`. browserContext: BrowserContext, page: Page, frame: Frame }`.
See [`method: BrowserContext.exposeBinding`] for the context-wide version. See [`method: BrowserContext.exposeBinding`] for the context-wide version.
@ -1370,8 +1370,8 @@ await page.setContent(`
Name of the function on the window object. Name of the function on the window object.
### param: Page.exposeBinding.playwrightBinding ### param: Page.exposeBinding.callback
- `playwrightBinding` <[function]> - `callback` <[function]>
Callback function that will be called in the Playwright's context. Callback function that will be called in the Playwright's context.
@ -1384,10 +1384,10 @@ supported. When passing by value, multiple arguments are supported.
## async method: Page.exposeFunction ## async method: Page.exposeFunction
The method adds a function called [`param: name`] on the `window` object of every frame in the page. When called, the The method adds a function called [`param: name`] on the `window` object of every frame in the page. When called, the
function executes [`param: playwrightFunction`] and returns a [Promise] which resolves to the return value of [`param: function executes [`param: callback`] and returns a [Promise] which resolves to the return value of [`param:
playwrightFunction`]. callback`].
If the [`param: playwrightFunction`] returns a [Promise], it will be awaited. If the [`param: callback`] returns a [Promise], it will be awaited.
See [`method: BrowserContext.exposeFunction`] for context-wide exposed function. See [`method: BrowserContext.exposeFunction`] for context-wide exposed function.
@ -1450,8 +1450,8 @@ const fs = require('fs');
Name of the function on the window object Name of the function on the window object
### param: Page.exposeFunction.playwrightFunction ### param: Page.exposeFunction.callback
- `playwrightFunction` <[function]> - `callback` <[function]>
Callback function which will be called in Playwright's context. Callback function which will be called in Playwright's context.
@ -1504,7 +1504,7 @@ const frame = page.frame({ url: /.*domain.*/ });
### param: Page.frame.frameSelector ### param: Page.frame.frameSelector
- `frameSelector` <[string]|[Object]> - `frameSelector` <[string]|[Object]>
- `name` <[string]> Frame name specified in the `iframe`'s `name` attribute. Optional. - `name` <[string]> Frame name specified in the `iframe`'s `name` attribute. Optional.
- `url` <[string]|[RegExp]|[Function]> A glob pattern, regex pattern or predicate receiving frame's `url` as a [URL] object. Optional. - `url` <[string]|[RegExp]|[function]\([URL]\):[boolean]> A glob pattern, regex pattern or predicate receiving frame's `url` as a [URL] object. Optional.
Frame name or other frame lookup options. Frame name or other frame lookup options.
@ -1705,7 +1705,7 @@ The [`option: format`] options are:
> 2. Page styles are not visible inside templates. > 2. Page styles are not visible inside templates.
### option: Page.pdf.path ### option: Page.pdf.path
- `path` <[string]> - `path` <[path]>
The file path to save the PDF to. If [`option: path`] is a relative path, then it is resolved relative to the current The file path to save the PDF to. If [`option: path`] is a relative path, then it is resolved relative to the current
working directory. If no path is provided, the PDF won't be saved to the disk. working directory. If no path is provided, the PDF won't be saved to the disk.
@ -1891,7 +1891,7 @@ Returns the buffer with the captured screenshot.
discussion. discussion.
### option: Page.screenshot.path ### option: Page.screenshot.path
- `path` <[string]> - `path` <[path]>
The file path to save the image to. The screenshot type will be inferred from file extension. If [`option: path`] is a The file path to save the image to. The screenshot type will be inferred from file extension. If [`option: path`] is a
relative path, then it is resolved relative to the current working directory. If no path is provided, the image won't be relative path, then it is resolved relative to the current working directory. If no path is provided, the image won't be
@ -2314,7 +2314,7 @@ Shortcut for main frame's [`method: Frame.waitForNavigation`].
### option: Page.waitForNavigation.timeout = %%-navigation-timeout-%% ### option: Page.waitForNavigation.timeout = %%-navigation-timeout-%%
### option: Page.waitForNavigation.url ### option: Page.waitForNavigation.url
- `url` <[string]|[RegExp]|[Function]> - `url` <[string]|[RegExp]|[function]\([URL]\):[boolean]>
A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation.
@ -2336,7 +2336,7 @@ await page.waitForRequest(request => request.url().searchParams.get('foo') === '
``` ```
### param: Page.waitForRequest.urlOrPredicate ### param: Page.waitForRequest.urlOrPredicate
- `urlOrPredicate` <[string]|[RegExp]|[Function]> - `urlOrPredicate` <[string]|[RegExp]|[function]\([Request]\):[boolean]>
Request URL string, regex or predicate receiving [Request] object. Request URL string, regex or predicate receiving [Request] object.
@ -2562,7 +2562,7 @@ Adds a `<script>` tag into the page with the desired url or content.
### param: Frame.addScriptTag.params ### param: Frame.addScriptTag.params
- `params` <[Object]> - `params` <[Object]>
- `url` <[string]> URL of a script to be added. Optional. - `url` <[string]> URL of a script to be added. Optional.
- `path` <[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` <[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.
- `content` <[string]> Raw JavaScript content to be injected into frame. Optional. - `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. - `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.
@ -2577,7 +2577,7 @@ content.
### param: Frame.addStyleTag.params ### param: Frame.addStyleTag.params
- `params` <[Object]> - `params` <[Object]>
- `url` <[string]> URL of the `<link>` tag. Optional. - `url` <[string]> URL of the `<link>` tag. Optional.
- `path` <[string]> 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. - `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.
- `content` <[string]> Raw CSS content to be injected into frame. Optional. - `content` <[string]> Raw CSS content to be injected into frame. Optional.
## async method: Frame.check ## async method: Frame.check
@ -3245,7 +3245,7 @@ considered a navigation.
### option: Frame.waitForNavigation.timeout = %%-navigation-timeout-%% ### option: Frame.waitForNavigation.timeout = %%-navigation-timeout-%%
### option: Frame.waitForNavigation.url ### option: Frame.waitForNavigation.url
- `url` <[string]|[RegExp]|[Function]> - `url` <[string]|[RegExp]|[function]\([URL]\):[boolean]>
URL string, URL regex pattern or predicate receiving [URL] to match while waiting for the navigation. URL string, URL regex pattern or predicate receiving [URL] to match while waiting for the navigation.
@ -3668,7 +3668,7 @@ This method waits for the [actionability](./actionability.md) checks, then scrol
screenshot. If the element is detached from DOM, the method throws an error. screenshot. If the element is detached from DOM, the method throws an error.
### option: ElementHandle.screenshot.path ### option: ElementHandle.screenshot.path
- `path` <[string]> - `path` <[path]>
The file path to save the image to. The screenshot type will be inferred from file extension. If [`option: path`] is a The file path to save the image to. The screenshot type will be inferred from file extension. If [`option: path`] is a
relative path, then it is resolved relative to the current working directory. If no path is provided, the image won't be relative path, then it is resolved relative to the current working directory. If no path is provided, the image won't be
@ -4119,7 +4119,7 @@ Returns path to the downloaded file in case of successful download.
Saves the download to a user-specified path. Saves the download to a user-specified path.
### param: Download.saveAs.path ### param: Download.saveAs.path
- `path` <[string]> - `path` <[path]>
Path where the download should be saved. Path where the download should be saved.
@ -4700,7 +4700,7 @@ contain `[a-zA-Z0-9_]` characters.
### param: Selectors.register.script ### param: Selectors.register.script
- `script` <[function]|[string]|[Object]> - `script` <[function]|[string]|[Object]>
- `path` <[string]> Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to the current working directory. Optional. - `path` <[path]> Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to the current working directory. Optional.
- `content` <[string]> Raw script content. Optional. - `content` <[string]> Raw script content. Optional.
Script that evaluates to a selector engine instance. Script that evaluates to a selector engine instance.
@ -4793,7 +4793,7 @@ await page.route('**/xhr_endpoint', route => route.fulfill({ path: 'mock_data.js
- `headers` <[Object]<[string], [string]>> Optional response headers. Header values will be converted to a string. - `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. - `contentType` <[string]> If set, equals to setting `Content-Type` response header.
- `body` <[string]|[Buffer]> Optional response body. - `body` <[string]|[Buffer]> Optional response body.
- `path` <[string]> 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. - `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 that will fulfill this route's request.
@ -5116,7 +5116,7 @@ Whether to run browser in headless mode. More details for
[`option: devtools`] option is `true`. [`option: devtools`] option is `true`.
### option: BrowserType.launch.executablePath ### option: BrowserType.launch.executablePath
- `executablePath` <[string]> - `executablePath` <[path]>
Path to a browser executable to run instead of the bundled one. If [`option: executablePath`] is a relative path, then Path to a browser executable to run instead of the bundled one. If [`option: executablePath`] is a relative path, then
it is resolved relative to the current working directory. Note that Playwright only works with the bundled Chromium, it is resolved relative to the current working directory. Note that Playwright only works with the bundled Chromium,
@ -5144,7 +5144,7 @@ array is given, then filters out the given default arguments. Dangerous option;
Network proxy settings. Network proxy settings.
### option: BrowserType.launch.downloadsPath ### option: BrowserType.launch.downloadsPath
- `downloadsPath` <[string]> - `downloadsPath` <[path]>
If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is
deleted when browser is closed. deleted when browser is closed.
@ -5211,7 +5211,7 @@ Launches browser that uses persistent storage located at [`param: userDataDir`]
this context will automatically close the browser. this context will automatically close the browser.
### param: BrowserType.launchPersistentContext.userDataDir ### param: BrowserType.launchPersistentContext.userDataDir
- `userDataDir` <[string]> - `userDataDir` <[path]>
Path to a User Data Directory, which stores browser session data like cookies and local storage. More details for Path to a User Data Directory, which stores browser session data like cookies and local storage. More details for
[Chromium](https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md) and [Chromium](https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md) and
@ -5226,7 +5226,7 @@ Whether to run browser in headless mode. More details for
[`option: devtools`] option is `true`. [`option: devtools`] option is `true`.
### option: BrowserType.launchPersistentContext.executablePath ### option: BrowserType.launchPersistentContext.executablePath
- `executablePath` <[string]> - `executablePath` <[path]>
Path to a browser executable to run instead of the bundled one. If [`option: executablePath`] is a relative path, then Path to a browser executable to run instead of the bundled one. If [`option: executablePath`] is a relative path, then
it is resolved relative to the current working directory. **BEWARE**: Playwright is only guaranteed to work with the it is resolved relative to the current working directory. **BEWARE**: Playwright is only guaranteed to work with the
@ -5254,7 +5254,7 @@ arguments. Dangerous option; use with care. Defaults to `false`.
Network proxy settings. Network proxy settings.
### option: BrowserType.launchPersistentContext.downloadsPath ### option: BrowserType.launchPersistentContext.downloadsPath
- `downloadsPath` <[string]> - `downloadsPath` <[path]>
If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is
deleted when browser is closed. deleted when browser is closed.
@ -5339,7 +5339,7 @@ Whether to run browser in headless mode. More details for
Port to use for the web socket. Defaults to 0 that picks any available port. Port to use for the web socket. Defaults to 0 that picks any available port.
### option: BrowserType.launchServer.executablePath ### option: BrowserType.launchServer.executablePath
- `executablePath` <[string]> - `executablePath` <[path]>
Path to a browser executable to run instead of the bundled one. If [`option: executablePath`] is a relative path, then Path to a browser executable to run instead of the bundled one. If [`option: executablePath`] is a relative path, then
it is resolved relative to the current working directory. **BEWARE**: Playwright is only guaranteed to work with the it is resolved relative to the current working directory. **BEWARE**: Playwright is only guaranteed to work with the
@ -5367,7 +5367,7 @@ arguments. Dangerous option; use with care. Defaults to `false`.
Network proxy settings. Network proxy settings.
### option: BrowserType.launchServer.downloadsPath ### option: BrowserType.launchServer.downloadsPath
- `downloadsPath` <[string]> - `downloadsPath` <[path]>
If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is
deleted when browser is closed. deleted when browser is closed.
@ -5510,7 +5510,7 @@ Only one trace can be active at a time per browser.
Optional, if specified, tracing includes screenshots of the given page. Optional, if specified, tracing includes screenshots of the given page.
### option: ChromiumBrowser.startTracing.path ### option: ChromiumBrowser.startTracing.path
- `path` <[string]> - `path` <[path]>
A path to write the trace file to. A path to write the trace file to.

View file

@ -25,7 +25,7 @@
"watch": "node utils/watch.js", "watch": "node utils/watch.js",
"test-types": "node utils/generate_types/ && npx -p typescript@3.7.5 tsc -p utils/generate_types/test/tsconfig.json && tsc -p ./test/", "test-types": "node utils/generate_types/ && npx -p typescript@3.7.5 tsc -p utils/generate_types/test/tsconfig.json && tsc -p ./test/",
"generate-channels": "node utils/generate_channels.js", "generate-channels": "node utils/generate_channels.js",
"generate-api-json": "node utils/doclint/generateApiJson.js > docs/api.json", "generate-api-json": "node utils/doclint/generateApiJson.js > api.json",
"roll-browser": "node utils/roll_browser.js", "roll-browser": "node utils/roll_browser.js",
"coverage": "node test/checkCoverage.js", "coverage": "node test/checkCoverage.js",
"check-deps": "node utils/check_deps.js", "check-deps": "node utils/check_deps.js",

View file

@ -126,7 +126,7 @@ if (!args.some(arg => arg === '--no-cleanup')) {
for (const file of package.files) for (const file of package.files)
await copyToPackage(path.join(ROOT_PATH, file), path.join(packagePath, file)); await copyToPackage(path.join(ROOT_PATH, file), path.join(packagePath, file));
await copyToPackage(path.join(ROOT_PATH, 'docs/api.json'), path.join(packagePath, 'api.json')); await copyToPackage(path.join(ROOT_PATH, 'api.json'), path.join(packagePath, 'api.json'));
await copyToPackage(path.join(ROOT_PATH, 'src/protocol/protocol.yml'), path.join(packagePath, 'protocol.yml')); await copyToPackage(path.join(ROOT_PATH, 'src/protocol/protocol.yml'), path.join(packagePath, 'protocol.yml'));
// 4. Generate package.json // 4. Generate package.json

View file

@ -184,17 +184,17 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel,
}); });
} }
async exposeBinding(name: string, playwrightBinding: (source: structs.BindingSource, ...args: any[]) => any, options: { handle?: boolean } = {}): Promise<void> { async exposeBinding(name: string, callback: (source: structs.BindingSource, ...args: any[]) => any, options: { handle?: boolean } = {}): Promise<void> {
return this._wrapApiCall('browserContext.exposeBinding', async () => { return this._wrapApiCall('browserContext.exposeBinding', async () => {
await this._channel.exposeBinding({ name, needsHandle: options.handle }); await this._channel.exposeBinding({ name, needsHandle: options.handle });
this._bindings.set(name, playwrightBinding); this._bindings.set(name, callback);
}); });
} }
async exposeFunction(name: string, playwrightFunction: Function): Promise<void> { async exposeFunction(name: string, callback: Function): Promise<void> {
return this._wrapApiCall('browserContext.exposeFunction', async () => { return this._wrapApiCall('browserContext.exposeFunction', async () => {
await this._channel.exposeBinding({ name }); await this._channel.exposeBinding({ name });
const binding = (source: structs.BindingSource, ...args: any[]) => playwrightFunction(...args); const binding = (source: structs.BindingSource, ...args: any[]) => callback(...args);
this._bindings.set(name, binding); this._bindings.set(name, binding);
}); });
} }

View file

@ -304,18 +304,18 @@ export class Page extends ChannelOwner<channels.PageChannel, channels.PageInitia
return this._attributeToPage(() => this._mainFrame.addStyleTag(params)); return this._attributeToPage(() => this._mainFrame.addStyleTag(params));
} }
async exposeFunction(name: string, playwrightFunction: Function) { async exposeFunction(name: string, callback: Function) {
return this._wrapApiCall('page.exposeFunction', async () => { return this._wrapApiCall('page.exposeFunction', async () => {
await this._channel.exposeBinding({ name }); await this._channel.exposeBinding({ name });
const binding = (source: structs.BindingSource, ...args: any[]) => playwrightFunction(...args); const binding = (source: structs.BindingSource, ...args: any[]) => callback(...args);
this._bindings.set(name, binding); this._bindings.set(name, binding);
}); });
} }
async exposeBinding(name: string, playwrightBinding: (source: structs.BindingSource, ...args: any[]) => any, options: { handle?: boolean } = {}) { async exposeBinding(name: string, callback: (source: structs.BindingSource, ...args: any[]) => any, options: { handle?: boolean } = {}) {
return this._wrapApiCall('page.exposeBinding', async () => { return this._wrapApiCall('page.exposeBinding', async () => {
await this._channel.exposeBinding({ name, needsHandle: options.handle }); await this._channel.exposeBinding({ name, needsHandle: options.handle });
this._bindings.set(name, playwrightBinding); this._bindings.set(name, callback);
}); });
} }

53
types/types.d.ts vendored
View file

@ -288,14 +288,14 @@ export interface Page {
/** /**
* The method adds a function called `name` on the `window` object of every frame in this page. When called, the function * The method adds a function called `name` on the `window` object of every frame in this page. When called, the function
* executes `playwrightBinding` and returns a [Promise] which resolves to the return value of `playwrightBinding`. If the * executes `callback` and returns a [Promise] which resolves to the return value of `callback`. If the `callback` returns
* `playwrightBinding` returns a [Promise], it will be awaited. * a [Promise], it will be awaited.
* *
* The first argument of the `playwrightBinding` function contains information about the caller: `{ browserContext: * The first argument of the `callback` function contains information about the caller: `{ browserContext: BrowserContext,
* BrowserContext, page: Page, frame: Frame }`. * page: Page, frame: Frame }`.
* *
* See * See
* [browserContext.exposeBinding(name, playwrightBinding[, options])](https://github.com/microsoft/playwright/blob/master/docs/api.md#browsercontextexposebindingname-playwrightbinding-options) * [browserContext.exposeBinding(name, callback[, options])](https://github.com/microsoft/playwright/blob/master/docs/api.md#browsercontextexposebindingname-callback-options)
* for the context-wide version. * for the context-wide version.
* *
* > **NOTE** Functions installed via `page.exposeBinding` survive navigations. * > **NOTE** Functions installed via `page.exposeBinding` survive navigations.
@ -339,7 +339,7 @@ export interface Page {
* ``` * ```
* *
* @param name Name of the function on the window object. * @param name Name of the function on the window object.
* @param playwrightBinding Callback function that will be called in the Playwright's context. * @param callback Callback function that will be called in the Playwright's context.
* @param options * @param options
*/ */
exposeBinding(name: string, playwrightBinding: (source: BindingSource, arg: JSHandle) => any, options: { handle: true }): Promise<void>; exposeBinding(name: string, playwrightBinding: (source: BindingSource, arg: JSHandle) => any, options: { handle: true }): Promise<void>;
@ -1695,12 +1695,12 @@ export interface Page {
/** /**
* The method adds a function called `name` on the `window` object of every frame in the page. When called, the function * The method adds a function called `name` on the `window` object of every frame in the page. When called, the function
* executes `playwrightFunction` and returns a [Promise] which resolves to the return value of `playwrightFunction`. * executes `callback` and returns a [Promise] which resolves to the return value of `callback`.
* *
* If the `playwrightFunction` returns a [Promise], it will be awaited. * If the `callback` returns a [Promise], it will be awaited.
* *
* See * See
* [browserContext.exposeFunction(name, playwrightFunction)](https://github.com/microsoft/playwright/blob/master/docs/api.md#browsercontextexposefunctionname-playwrightfunction) * [browserContext.exposeFunction(name, callback)](https://github.com/microsoft/playwright/blob/master/docs/api.md#browsercontextexposefunctionname-callback)
* for context-wide exposed function. * for context-wide exposed function.
* *
* > **NOTE** Functions installed via `page.exposeFunction` survive navigations. * > **NOTE** Functions installed via `page.exposeFunction` survive navigations.
@ -1758,9 +1758,9 @@ export interface Page {
* ``` * ```
* *
* @param name Name of the function on the window object * @param name Name of the function on the window object
* @param playwrightFunction Callback function which will be called in Playwright's context. * @param callback Callback function which will be called in Playwright's context.
*/ */
exposeFunction(name: string, playwrightFunction: Function): Promise<void>; exposeFunction(name: string, callback: Function): Promise<void>;
/** /**
* This method waits for an element matching `selector`, waits for [actionability](https://github.com/microsoft/playwright/blob/master/docs/actionability.md) checks, focuses the * This method waits for an element matching `selector`, waits for [actionability](https://github.com/microsoft/playwright/blob/master/docs/actionability.md) checks, focuses the
@ -1839,7 +1839,7 @@ export interface Page {
/** /**
* A glob pattern, regex pattern or predicate receiving frame's `url` as a [URL] object. Optional. * A glob pattern, regex pattern or predicate receiving frame's `url` as a [URL] object. Optional.
*/ */
url?: string|RegExp|Function; url?: string|RegExp|((url: URL) => boolean);
}): null|Frame; }): null|Frame;
/** /**
@ -3122,7 +3122,7 @@ export interface Page {
/** /**
* A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. * A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation.
*/ */
url?: string|RegExp|Function; url?: string|RegExp|((url: URL) => boolean);
/** /**
* When to consider operation succeeded, defaults to `load`. Events can be either: * When to consider operation succeeded, defaults to `load`. Events can be either:
@ -3149,7 +3149,7 @@ export interface Page {
* @param urlOrPredicate Request URL string, regex or predicate receiving [Request] object. * @param urlOrPredicate Request URL string, regex or predicate receiving [Request] object.
* @param options * @param options
*/ */
waitForRequest(urlOrPredicate: string|RegExp|Function, options?: { waitForRequest(urlOrPredicate: string|RegExp|((request: Request) => boolean), options?: {
/** /**
* Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can be * Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can be
* changed by using the * changed by using the
@ -4426,7 +4426,7 @@ export interface Frame {
/** /**
* URL string, URL regex pattern or predicate receiving [URL] to match while waiting for the navigation. * URL string, URL regex pattern or predicate receiving [URL] to match while waiting for the navigation.
*/ */
url?: string|RegExp|Function; url?: string|RegExp|((url: URL) => boolean);
/** /**
* When to consider operation succeeded, defaults to `load`. Events can be either: * When to consider operation succeeded, defaults to `load`. Events can be either:
@ -4471,14 +4471,14 @@ export interface Frame {
export interface BrowserContext { export interface BrowserContext {
/** /**
* The method adds a function called `name` on the `window` object of every frame in every page in the context. When * The method adds a function called `name` on the `window` object of every frame in every page in the context. When
* called, the function executes `playwrightBinding` and returns a [Promise] which resolves to the return value of * called, the function executes `callback` and returns a [Promise] which resolves to the return value of `callback`. If
* `playwrightBinding`. If the `playwrightBinding` returns a [Promise], it will be awaited. * the `callback` returns a [Promise], it will be awaited.
* *
* The first argument of the `playwrightBinding` function contains information about the caller: `{ browserContext: * The first argument of the `callback` function contains information about the caller: `{ browserContext: BrowserContext,
* BrowserContext, page: Page, frame: Frame }`. * page: Page, frame: Frame }`.
* *
* See * See
* [page.exposeBinding(name, playwrightBinding[, options])](https://github.com/microsoft/playwright/blob/master/docs/api.md#pageexposebindingname-playwrightbinding-options) * [page.exposeBinding(name, callback[, options])](https://github.com/microsoft/playwright/blob/master/docs/api.md#pageexposebindingname-callback-options)
* for page-only version. * for page-only version.
* *
* An example of exposing page URL to all frames in all pages in the context: * An example of exposing page URL to all frames in all pages in the context:
@ -4520,7 +4520,7 @@ export interface BrowserContext {
* ``` * ```
* *
* @param name Name of the function on the window object. * @param name Name of the function on the window object.
* @param playwrightBinding Callback function that will be called in the Playwright's context. * @param callback Callback function that will be called in the Playwright's context.
* @param options * @param options
*/ */
exposeBinding(name: string, playwrightBinding: (source: BindingSource, arg: JSHandle) => any, options: { handle: true }): Promise<void>; exposeBinding(name: string, playwrightBinding: (source: BindingSource, arg: JSHandle) => any, options: { handle: true }): Promise<void>;
@ -4831,13 +4831,12 @@ export interface BrowserContext {
/** /**
* The method adds a function called `name` on the `window` object of every frame in every page in the context. When * The method adds a function called `name` on the `window` object of every frame in every page in the context. When
* called, the function executes `playwrightFunction` and returns a [Promise] which resolves to the return value of * called, the function executes `callback` and returns a [Promise] which resolves to the return value of `callback`.
* `playwrightFunction`.
* *
* If the `playwrightFunction` returns a [Promise], it will be awaited. * If the `callback` returns a [Promise], it will be awaited.
* *
* See * See
* [page.exposeFunction(name, playwrightFunction)](https://github.com/microsoft/playwright/blob/master/docs/api.md#pageexposefunctionname-playwrightfunction) * [page.exposeFunction(name, callback)](https://github.com/microsoft/playwright/blob/master/docs/api.md#pageexposefunctionname-callback)
* for page-only version. * for page-only version.
* *
* An example of adding an `md5` function to all pages in the context: * An example of adding an `md5` function to all pages in the context:
@ -4865,9 +4864,9 @@ export interface BrowserContext {
* ``` * ```
* *
* @param name Name of the function on the window object. * @param name Name of the function on the window object.
* @param playwrightFunction Callback function that will be called in the Playwright's context. * @param callback Callback function that will be called in the Playwright's context.
*/ */
exposeFunction(name: string, playwrightFunction: Function): Promise<void>; exposeFunction(name: string, callback: Function): Promise<void>;
/** /**
* Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin if * Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin if

View file

@ -32,6 +32,7 @@ const PROJECT_DIR = path.join(__dirname, '..', '..');
if (clazz) if (clazz)
return `\`${clazz.name}\``; return `\`${clazz.name}\``;
}); });
outline.copyDocsFromSuperclasses([]);
outline.generateSourceCodeComments(); outline.generateSourceCodeComments();
const result = serialize(outline); const result = serialize(outline);
console.log(JSON.stringify(result)); console.log(JSON.stringify(result));

View file

@ -393,6 +393,8 @@ function stringifySimpleType(parsedType) {
} else if (parsedType.name === 'function') { } else if (parsedType.name === 'function') {
out = 'Function'; out = 'Function';
} }
if (out === 'path')
return 'string';
if (parsedType.nullable) if (parsedType.nullable)
out = 'null|' + out; out = 'null|' + out;
if (parsedType.template) if (parsedType.template)