page.getByText(/^hello$/i);
**Arguments**
* `text` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") | [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp "RegExp")[#](#page-get-by-text-option-text)
Text to locate the element for.
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `exact` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_[#](#page-get-by-text-option-exact)
Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a regular expression. Note that exact match still trims whitespace.
**Returns**
* [Locator](/docs/api/class-locator "Locator")[#](#page-get-by-text-return)
**Details**
Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into one, turns line breaks into spaces and ignores leading and trailing whitespace.
Input elements of the type `button` and `submit` are matched by their `value` instead of the text content. For example, locating by text `"Log in"` matches `
`.
* * *
### getByTitle[](#page-get-by-title "Direct link to getByTitle")
Added in: v1.27 page.getByTitle
Allows locating elements by their title attribute.
**Usage**
Consider the following DOM structure.
25 issues
You can check the issues count after locating it by the title text:
await expect(page.getByTitle('Issues count')).toHaveText('25 issues');
**Arguments**
* `text` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") | [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp "RegExp")[#](#page-get-by-title-option-text)
Text to locate the element for.
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `exact` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_[#](#page-get-by-title-option-exact)
Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a regular expression. Note that exact match still trims whitespace.
**Returns**
* [Locator](/docs/api/class-locator "Locator")[#](#page-get-by-title-return)
* * *
### goBack[](#page-go-back "Direct link to goBack")
Added before v1.9 page.goBack
Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. If cannot go back, returns `null`.
Navigate to the previous page in history.
**Usage**
await page.goBack();await page.goBack(options);
**Arguments**
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `timeout` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-go-back-option-timeout)
Maximum operation time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via `navigationTimeout` option in the config, or by using the [browserContext.setDefaultNavigationTimeout()](/docs/api/class-browsercontext#browser-context-set-default-navigation-timeout), [browserContext.setDefaultTimeout()](/docs/api/class-browsercontext#browser-context-set-default-timeout), [page.setDefaultNavigationTimeout()](/docs/api/class-page#page-set-default-navigation-timeout) or [page.setDefaultTimeout()](/docs/api/class-page#page-set-default-timeout) methods.
* `waitUntil` "load" | "domcontentloaded" | "networkidle" | "commit" _(optional)_[#](#page-go-back-option-wait-until)
When to consider operation succeeded, defaults to `load`. Events can be either:
* `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
* `'load'` - consider operation to be finished when the `load` event is fired.
* `'networkidle'` - **DISCOURAGED** consider operation to be finished when there are no network connections for at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
* `'commit'` - consider operation to be finished when network response is received and the document started loading.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[null](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null "null") | [Response](/docs/api/class-response "Response")\>[#](#page-go-back-return)
* * *
### goForward[](#page-go-forward "Direct link to goForward")
Added before v1.9 page.goForward
Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. If cannot go forward, returns `null`.
Navigate to the next page in history.
**Usage**
await page.goForward();await page.goForward(options);
**Arguments**
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `timeout` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-go-forward-option-timeout)
Maximum operation time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via `navigationTimeout` option in the config, or by using the [browserContext.setDefaultNavigationTimeout()](/docs/api/class-browsercontext#browser-context-set-default-navigation-timeout), [browserContext.setDefaultTimeout()](/docs/api/class-browsercontext#browser-context-set-default-timeout), [page.setDefaultNavigationTimeout()](/docs/api/class-page#page-set-default-navigation-timeout) or [page.setDefaultTimeout()](/docs/api/class-page#page-set-default-timeout) methods.
* `waitUntil` "load" | "domcontentloaded" | "networkidle" | "commit" _(optional)_[#](#page-go-forward-option-wait-until)
When to consider operation succeeded, defaults to `load`. Events can be either:
* `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
* `'load'` - consider operation to be finished when the `load` event is fired.
* `'networkidle'` - **DISCOURAGED** consider operation to be finished when there are no network connections for at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
* `'commit'` - consider operation to be finished when network response is received and the document started loading.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[null](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null "null") | [Response](/docs/api/class-response "Response")\>[#](#page-go-forward-return)
* * *
### goto[](#page-goto "Direct link to goto")
Added before v1.9 page.goto
Returns the main resource response. In case of multiple redirects, the navigation will resolve with the first non-redirect response.
The method will throw an error if:
* there's an SSL error (e.g. in case of self-signed certificates).
* target URL is invalid.
* the [timeout](/docs/api/class-page#page-goto-option-timeout) is exceeded during navigation.
* the remote server does not respond or is unreachable.
* the main resource failed to load.
The method will not throw an error when any valid HTTP status code is returned by the remote server, including 404 "Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling [response.status()](/docs/api/class-response#response-status).
note
The method either throws an error or returns a main resource response. The only exceptions are navigation to `about:blank` or navigation to the same URL with a different hash, which would succeed and return `null`.
note
Headless mode doesn't support navigation to a PDF document. See the [upstream issue](https://bugs.chromium.org/p/chromium/issues/detail?id=761295).
**Usage**
await page.goto(url);await page.goto(url, options);
**Arguments**
* `url` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")[#](#page-goto-option-url)
URL to navigate page to. The url should include scheme, e.g. `https://`. When a [baseURL](/docs/api/class-browser#browser-new-context-option-base-url) via the context options was provided and the passed URL is a path, it gets merged via the [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor.
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `referer` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") _(optional)_[#](#page-goto-option-referer)
Referer header value. If provided it will take preference over the referer header value set by [page.setExtraHTTPHeaders()](/docs/api/class-page#page-set-extra-http-headers).
* `timeout` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-goto-option-timeout)
Maximum operation time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via `navigationTimeout` option in the config, or by using the [browserContext.setDefaultNavigationTimeout()](/docs/api/class-browsercontext#browser-context-set-default-navigation-timeout), [browserContext.setDefaultTimeout()](/docs/api/class-browsercontext#browser-context-set-default-timeout), [page.setDefaultNavigationTimeout()](/docs/api/class-page#page-set-default-navigation-timeout) or [page.setDefaultTimeout()](/docs/api/class-page#page-set-default-timeout) methods.
* `waitUntil` "load" | "domcontentloaded" | "networkidle" | "commit" _(optional)_[#](#page-goto-option-wait-until)
When to consider operation succeeded, defaults to `load`. Events can be either:
* `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
* `'load'` - consider operation to be finished when the `load` event is fired.
* `'networkidle'` - **DISCOURAGED** consider operation to be finished when there are no network connections for at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
* `'commit'` - consider operation to be finished when network response is received and the document started loading.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[null](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null "null") | [Response](/docs/api/class-response "Response")\>[#](#page-goto-return)
* * *
### isClosed[](#page-is-closed "Direct link to isClosed")
Added before v1.9 page.isClosed
Indicates that the page has been closed.
**Usage**
page.isClosed();
**Returns**
* [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")[#](#page-is-closed-return)
* * *
### locator[](#page-locator "Direct link to locator")
Added in: v1.14 page.locator
The method returns an element locator that can be used to perform actions on this page / frame. Locator is resolved to the element immediately before performing an action, so a series of actions on the same locator can in fact be performed on different DOM elements. That would happen if the DOM structure between those actions has changed.
[Learn more about locators](/docs/locators).
**Usage**
page.locator(selector);page.locator(selector, options);
**Arguments**
* `selector` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")[#](#page-locator-option-selector)
A selector to use when resolving DOM element.
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `has` [Locator](/docs/api/class-locator "Locator") _(optional)_[#](#page-locator-option-has)
Narrows down the results of the method to those which contain elements matching this relative locator. For example, `article` that has `text=Playwright` matches `
Playwright
`.
Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not the document root. For example, you can find `content` that has `div` in `
Playwright
`. However, looking for `content` that has `article div` will fail, because the inner locator must be relative and should not use any elements outside the `content`.
Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator](/docs/api/class-framelocator "FrameLocator")s.
* `hasNot` [Locator](/docs/api/class-locator "Locator") _(optional)_ Added in: v1.33[#](#page-locator-option-has-not)
Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the outer one. For example, `article` that does not have `div` matches `
Playwright `.
Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator](/docs/api/class-framelocator "FrameLocator")s.
* `hasNotText` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") | [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp "RegExp") _(optional)_ Added in: v1.33[#](#page-locator-option-has-not-text)
Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When passed a [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string"), matching is case-insensitive and searches for a substring.
* `hasText` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") | [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp "RegExp") _(optional)_[#](#page-locator-option-has-text)
Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string"), matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches `
Playwright
`.
**Returns**
* [Locator](/docs/api/class-locator "Locator")[#](#page-locator-return)
* * *
### mainFrame[](#page-main-frame "Direct link to mainFrame")
Added before v1.9 page.mainFrame
The page's main frame. Page is guaranteed to have a main frame which persists during navigations.
**Usage**
page.mainFrame();
**Returns**
* [Frame](/docs/api/class-frame "Frame")[#](#page-main-frame-return)
* * *
### opener[](#page-opener "Direct link to opener")
Added before v1.9 page.opener
Returns the opener for popup pages and `null` for others. If the opener has been closed already the returns `null`.
**Usage**
await page.opener();
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[null](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null "null") | [Page](/docs/api/class-page "Page")\>[#](#page-opener-return)
* * *
### pageErrors[](#page-page-errors "Direct link to pageErrors")
Added in: v1.56 page.pageErrors
Returns up to (currently) 200 last page errors from this page. See [page.on('pageerror')](/docs/api/class-page#page-event-page-error) for more details.
**Usage**
await page.pageErrors();
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Error](https://nodejs.org/api/errors.html#errors_class_error "Error")\>>[#](#page-page-errors-return)
* * *
### pause[](#page-pause "Direct link to pause")
Added in: v1.9 page.pause
Pauses script execution. Playwright will stop executing the script and wait for the user to either press the 'Resume' button in the page overlay or to call `playwright.resume()` in the DevTools console.
User can inspect selectors or perform manual steps while paused. Resume will continue running the original script from the place it was paused.
note
This method requires Playwright to be started in a headed mode, with a falsy [headless](/docs/api/class-browsertype#browser-type-launch-option-headless) option.
**Usage**
await page.pause();
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[void](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined "void")\>[#](#page-pause-return)
* * *
### pdf[](#page-pdf "Direct link to pdf")
Added before v1.9 page.pdf
Returns the PDF buffer.
`page.pdf()` generates a pdf of the page with `print` css media. To generate a pdf with `screen` media, call [page.emulateMedia()](/docs/api/class-page#page-emulate-media) before calling `page.pdf()`:
note
By default, `page.pdf()` generates a pdf with modified colors for printing. Use the [`-webkit-print-color-adjust`](https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-print-color-adjust) property to force rendering of exact colors.
**Usage**
// Generates a PDF with 'screen' media type.await page.emulateMedia({ media: 'screen' });await page.pdf({ path: 'page.pdf' });
The [width](/docs/api/class-page#page-pdf-option-width), [height](/docs/api/class-page#page-pdf-option-height), and [margin](/docs/api/class-page#page-pdf-option-margin) options accept values labeled with units. Unlabeled values are treated as pixels.
A few examples:
* `page.pdf({width: 100})` - prints with width set to 100 pixels
* `page.pdf({width: '100px'})` - prints with width set to 100 pixels
* `page.pdf({width: '10cm'})` - prints with width set to 10 centimeters.
All possible units are:
* `px` - pixel
* `in` - inch
* `cm` - centimeter
* `mm` - millimeter
The [format](/docs/api/class-page#page-pdf-option-format) options are:
* `Letter`: 8.5in x 11in
* `Legal`: 8.5in x 14in
* `Tabloid`: 11in x 17in
* `Ledger`: 17in x 11in
* `A0`: 33.1in x 46.8in
* `A1`: 23.4in x 33.1in
* `A2`: 16.54in x 23.4in
* `A3`: 11.7in x 16.54in
* `A4`: 8.27in x 11.7in
* `A5`: 5.83in x 8.27in
* `A6`: 4.13in x 5.83in
note
[headerTemplate](/docs/api/class-page#page-pdf-option-header-template) and [footerTemplate](/docs/api/class-page#page-pdf-option-footer-template) markup have the following limitations: > 1. Script tags inside templates are not evaluated. > 2. Page styles are not visible inside templates.
**Arguments**
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `displayHeaderFooter` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_[#](#page-pdf-option-display-header-footer)
Display header and footer. Defaults to `false`.
* `footerTemplate` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") _(optional)_[#](#page-pdf-option-footer-template)
HTML template for the print footer. Should use the same format as the [headerTemplate](/docs/api/class-page#page-pdf-option-header-template).
* `format` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") _(optional)_[#](#page-pdf-option-format)
Paper format. If set, takes priority over [width](/docs/api/class-page#page-pdf-option-width) or [height](/docs/api/class-page#page-pdf-option-height) options. Defaults to 'Letter'.
* `headerTemplate` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") _(optional)_[#](#page-pdf-option-header-template)
HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them:
* `'date'` formatted print date
* `'title'` document title
* `'url'` document location
* `'pageNumber'` current page number
* `'totalPages'` total pages in the document
* `height` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") | [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-pdf-option-height)
Paper height, accepts values labeled with units.
* `landscape` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_[#](#page-pdf-option-landscape)
Paper orientation. Defaults to `false`.
* `margin` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_[#](#page-pdf-option-margin)
* `top` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") | [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_
Top margin, accepts values labeled with units. Defaults to `0`.
* `right` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") | [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_
Right margin, accepts values labeled with units. Defaults to `0`.
* `bottom` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") | [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_
Bottom margin, accepts values labeled with units. Defaults to `0`.
* `left` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") | [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_
Left margin, accepts values labeled with units. Defaults to `0`.
Paper margins, defaults to none.
* `outline` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_ Added in: v1.42[#](#page-pdf-option-outline)
Whether or not to embed the document outline into the PDF. Defaults to `false`.
* `pageRanges` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") _(optional)_[#](#page-pdf-option-page-ranges)
Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
* `path` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") _(optional)_[#](#page-pdf-option-path)
The file path to save the PDF to. If [path](/docs/api/class-page#page-pdf-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.
* `preferCSSPageSize` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_[#](#page-pdf-option-prefer-css-page-size)
Give any CSS `@page` size declared in the page priority over what is declared in [width](/docs/api/class-page#page-pdf-option-width) and [height](/docs/api/class-page#page-pdf-option-height) or [format](/docs/api/class-page#page-pdf-option-format) options. Defaults to `false`, which will scale the content to fit the paper size.
* `printBackground` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_[#](#page-pdf-option-print-background)
Print background graphics. Defaults to `false`.
* `scale` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-pdf-option-scale)
Scale of the webpage rendering. Defaults to `1`. Scale amount must be between 0.1 and 2.
* `tagged` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_ Added in: v1.42[#](#page-pdf-option-tagged)
Whether or not to generate tagged (accessible) PDF. Defaults to `false`.
* `width` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") | [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-pdf-option-width)
Paper width, accepts values labeled with units.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Buffer](https://nodejs.org/api/buffer.html#buffer_class_buffer "Buffer")\>[#](#page-pdf-return)
* * *
### reload[](#page-reload "Direct link to reload")
Added before v1.9 page.reload
This method reloads the current page, in the same way as if the user had triggered a browser refresh. Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.
**Usage**
await page.reload();await page.reload(options);
**Arguments**
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `timeout` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-reload-option-timeout)
Maximum operation time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via `navigationTimeout` option in the config, or by using the [browserContext.setDefaultNavigationTimeout()](/docs/api/class-browsercontext#browser-context-set-default-navigation-timeout), [browserContext.setDefaultTimeout()](/docs/api/class-browsercontext#browser-context-set-default-timeout), [page.setDefaultNavigationTimeout()](/docs/api/class-page#page-set-default-navigation-timeout) or [page.setDefaultTimeout()](/docs/api/class-page#page-set-default-timeout) methods.
* `waitUntil` "load" | "domcontentloaded" | "networkidle" | "commit" _(optional)_[#](#page-reload-option-wait-until)
When to consider operation succeeded, defaults to `load`. Events can be either:
* `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
* `'load'` - consider operation to be finished when the `load` event is fired.
* `'networkidle'` - **DISCOURAGED** consider operation to be finished when there are no network connections for at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
* `'commit'` - consider operation to be finished when network response is received and the document started loading.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[null](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null "null") | [Response](/docs/api/class-response "Response")\>[#](#page-reload-return)
* * *
### removeAllListeners[](#page-remove-all-listeners "Direct link to removeAllListeners")
Added in: v1.47 page.removeAllListeners
Removes all the listeners of the given type (or all registered listeners if no type given). Allows to wait for async listeners to complete or to ignore subsequent errors from these listeners.
**Usage**
page.on('request', async request => { const response = await request.response(); const body = await response.body(); console.log(body.byteLength);});await page.goto('https://playwright.dev', { waitUntil: 'domcontentloaded' });// Waits for all the reported 'request' events to resolve.await page.removeAllListeners('request', { behavior: 'wait' });
**Arguments**
* `type` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") _(optional)_[#](#page-remove-all-listeners-option-type)
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `behavior` "wait" | "ignoreErrors" | "default" _(optional)_[#](#page-remove-all-listeners-option-behavior)
Specifies whether to wait for already running listeners and what to do if they throw errors:
* `'default'` - do not wait for current listener calls (if any) to finish, if the listener throws, it may result in unhandled error
* `'wait'` - wait for current listener calls (if any) to finish
* `'ignoreErrors'` - do not wait for current listener calls (if any) to finish, all errors thrown by the listeners after removal are silently caught
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[void](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined "void")\>[#](#page-remove-all-listeners-return)
* * *
### removeLocatorHandler[](#page-remove-locator-handler "Direct link to removeLocatorHandler")
Added in: v1.44 page.removeLocatorHandler
Removes all locator handlers added by [page.addLocatorHandler()](/docs/api/class-page#page-add-locator-handler) for a specific locator.
**Usage**
await page.removeLocatorHandler(locator);
**Arguments**
* `locator` [Locator](/docs/api/class-locator "Locator")[#](#page-remove-locator-handler-option-locator)
Locator passed to [page.addLocatorHandler()](/docs/api/class-page#page-add-locator-handler).
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[void](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined "void")\>[#](#page-remove-locator-handler-return)
* * *
### requestGC[](#page-request-gc "Direct link to requestGC")
Added in: v1.48 page.requestGC
Request the page to perform garbage collection. Note that there is no guarantee that all unreachable objects will be collected.
This is useful to help detect memory leaks. For example, if your page has a large object `'suspect'` that might be leaked, you can check that it does not leak by using a [`WeakRef`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef).
// 1. In your page, save a WeakRef for the "suspect".await page.evaluate(() => globalThis.suspectWeakRef = new WeakRef(suspect));// 2. Request garbage collection.await page.requestGC();// 3. Check that weak ref does not deref to the original object.expect(await page.evaluate(() => !globalThis.suspectWeakRef.deref())).toBe(true);
**Usage**
await page.requestGC();
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[void](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined "void")\>[#](#page-request-gc-return)
* * *
### requests[](#page-requests "Direct link to requests")
Added in: v1.56 page.requests
Returns up to (currently) 100 last network request from this page. See [page.on('request')](/docs/api/class-page#page-event-request) for more details.
Returned requests should be accessed immediately, otherwise they might be collected to prevent unbounded memory growth as new requests come in. Once collected, retrieving most information about the request is impossible.
Note that requests reported through the [page.on('request')](/docs/api/class-page#page-event-request) request are not collected, so there is a trade off between efficient memory usage with [page.requests()](/docs/api/class-page#page-requests) and the amount of available information reported through [page.on('request')](/docs/api/class-page#page-event-request).
**Usage**
await page.requests();
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Request](/docs/api/class-request "Request")\>>[#](#page-requests-return)
* * *
### route[](#page-route "Direct link to route")
Added before v1.9 page.route
Routing provides the capability to modify network requests that are made by a page.
Once routing is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
note
The handler will only be called for the first url if the response is a redirect.
note
[page.route()](/docs/api/class-page#page-route) will not intercept requests intercepted by Service Worker. See [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using request interception by setting [serviceWorkers](/docs/api/class-browser#browser-new-context-option-service-workers) to `'block'`.
note
[page.route()](/docs/api/class-page#page-route) will not intercept the first request of a popup page. Use [browserContext.route()](/docs/api/class-browsercontext#browser-context-route) instead.
**Usage**
An example of a naive handler that aborts all image requests:
const page = await browser.newPage();await page.route('**/*.{png,jpg,jpeg}', route => route.abort());await page.goto('https://example.com');await browser.close();
or the same snippet using a regex pattern instead:
const page = await browser.newPage();await page.route(/(\.png$)|(\.jpg$)/, route => route.abort());await page.goto('https://example.com');await browser.close();
It is possible to examine the request to decide the route action. For example, mocking all requests that contain some post data, and leaving all other requests as is:
await page.route('/api/**', async route => { if (route.request().postData().includes('my-string')) await route.fulfill({ body: 'mocked-data' }); else await route.continue();});
Page routes take precedence over browser context routes (set up with [browserContext.route()](/docs/api/class-browsercontext#browser-context-route)) when request matches both handlers.
To remove a route with its handler you can use [page.unroute()](/docs/api/class-page#page-unroute).
note
Enabling routing disables http cache.
**Arguments**
* `url` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") | [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp "RegExp") | [function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([URL](https://nodejs.org/api/url.html "URL")):[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")[#](#page-route-option-url)
A glob pattern, regex pattern, or predicate that receives a [URL](https://nodejs.org/api/url.html "URL") to match during routing. If [baseURL](/docs/api/class-browser#browser-new-context-option-base-url) is set in the context options and the provided URL is a string that does not start with `*`, it is resolved using the [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor.
* `handler` [function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([Route](/docs/api/class-route "Route"), [Request](/docs/api/class-request "Request")):[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")\> | [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")[#](#page-route-option-handler)
handler function to route the request.
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `times` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_ Added in: v1.15[#](#page-route-option-times)
How often a route should be used. By default it will be used every time.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[void](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined "void")\>[#](#page-route-return)
* * *
### routeFromHAR[](#page-route-from-har "Direct link to routeFromHAR")
Added in: v1.23 page.routeFromHAR
If specified the network requests that are made in the page will be served from the HAR file. Read more about [Replaying from HAR](/docs/mock#replaying-from-har).
Playwright will not serve requests intercepted by Service Worker from the HAR file. See [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using request interception by setting [serviceWorkers](/docs/api/class-browser#browser-new-context-option-service-workers) to `'block'`.
**Usage**
await page.routeFromHAR(har);await page.routeFromHAR(har, options);
**Arguments**
* `har` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")[#](#page-route-from-har-option-har)
Path to a [HAR](http://www.softwareishard.com/blog/har-12-spec) file with prerecorded network data. If `path` is a relative path, then it is resolved relative to the current working directory.
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `notFound` "abort" | "fallback" _(optional)_[#](#page-route-from-har-option-not-found)
* If set to 'abort' any request not found in the HAR file will be aborted.
* If set to 'fallback' missing requests will be sent to the network.
Defaults to abort.
* `update` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_[#](#page-route-from-har-option-update)
If specified, updates the given HAR with the actual network information instead of serving from file. The file is written to disk when [browserContext.close()](/docs/api/class-browsercontext#browser-context-close) is called.
* `updateContent` "embed" | "attach" _(optional)_ Added in: v1.32[#](#page-route-from-har-option-update-content)
Optional setting to control resource content management. If `attach` is specified, resources are persisted as separate files or entries in the ZIP archive. If `embed` is specified, content is stored inline the HAR file.
* `updateMode` "full" | "minimal" _(optional)_ Added in: v1.32[#](#page-route-from-har-option-update-mode)
When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to `minimal`.
* `url` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") | [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp "RegExp") _(optional)_[#](#page-route-from-har-option-url)
A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the pattern will be served from the HAR file. If not specified, all requests are served from the HAR file.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[void](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined "void")\>[#](#page-route-from-har-return)
* * *
### routeWebSocket[](#page-route-web-socket "Direct link to routeWebSocket")
Added in: v1.48 page.routeWebSocket
This method allows to modify websocket connections that are made by the page.
Note that only `WebSocket`s created after this method was called will be routed. It is recommended to call this method before navigating the page.
**Usage**
Below is an example of a simple mock that responds to a single message. See [WebSocketRoute](/docs/api/class-websocketroute "WebSocketRoute") for more details and examples.
await page.routeWebSocket('/ws', ws => { ws.onMessage(message => { if (message === 'request') ws.send('response'); });});
**Arguments**
* `url` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") | [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp "RegExp") | [function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([URL](https://nodejs.org/api/url.html "URL")):[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")[#](#page-route-web-socket-option-url)
Only WebSockets with the url matching this pattern will be routed. A string pattern can be relative to the [baseURL](/docs/api/class-browser#browser-new-context-option-base-url) context option.
* `handler` [function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([WebSocketRoute](/docs/api/class-websocketroute "WebSocketRoute")):[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")\> | [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")[#](#page-route-web-socket-option-handler)
Handler function to route the WebSocket.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[void](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined "void")\>[#](#page-route-web-socket-return)
* * *
### screenshot[](#page-screenshot "Direct link to screenshot")
Added before v1.9 page.screenshot
Returns the buffer with the captured screenshot.
**Usage**
await page.screenshot();await page.screenshot(options);
**Arguments**
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `animations` "disabled" | "allow" _(optional)_[#](#page-screenshot-option-animations)
When set to `"disabled"`, stops CSS animations, CSS transitions and Web Animations. Animations get different treatment depending on their duration:
* finite animations are fast-forwarded to completion, so they'll fire `transitionend` event.
* infinite animations are canceled to initial state, and then played over after the screenshot.
Defaults to `"allow"` that leaves animations untouched.
* `caret` "hide" | "initial" _(optional)_[#](#page-screenshot-option-caret)
When set to `"hide"`, screenshot will hide text caret. When set to `"initial"`, text caret behavior will not be changed. Defaults to `"hide"`.
* `clip` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_[#](#page-screenshot-option-clip)
* `x` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")
x-coordinate of top-left corner of clip area
* `y` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")
y-coordinate of top-left corner of clip area
* `width` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")
width of clipping area
* `height` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")
height of clipping area
An object which specifies clipping of the resulting image.
* `fullPage` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_[#](#page-screenshot-option-full-page)
When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to `false`.
* `mask` [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Locator](/docs/api/class-locator "Locator")\> _(optional)_[#](#page-screenshot-option-mask)
Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box `#FF00FF` (customized by [maskColor](/docs/api/class-page#page-screenshot-option-mask-color)) that completely covers its bounding box. The mask is also applied to invisible elements, see [Matching only visible elements](/docs/locators#matching-only-visible-elements) to disable that.
* `maskColor` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") _(optional)_ Added in: v1.35[#](#page-screenshot-option-mask-color)
Specify the color of the overlay box for masked elements, in [CSS color format](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value). Default color is pink `#FF00FF`.
* `omitBackground` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_[#](#page-screenshot-option-omit-background)
Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images. Defaults to `false`.
* `path` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") _(optional)_[#](#page-screenshot-option-path)
The file path to save the image to. The screenshot type will be inferred from file extension. If [path](/docs/api/class-page#page-screenshot-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 saved to the disk.
* `quality` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-screenshot-option-quality)
The quality of the image, between 0-100. Not applicable to `png` images.
* `scale` "css" | "device" _(optional)_[#](#page-screenshot-option-scale)
When set to `"css"`, screenshot will have a single pixel per each css pixel on the page. For high-dpi devices, this will keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so screenshots of high-dpi devices will be twice as large or even larger.
Defaults to `"device"`.
* `style` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") _(optional)_ Added in: v1.41[#](#page-screenshot-option-style)
Text of the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make elements invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces the Shadow DOM and applies to the inner frames.
* `timeout` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-screenshot-option-timeout)
Maximum time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via `actionTimeout` option in the config, or by using the [browserContext.setDefaultTimeout()](/docs/api/class-browsercontext#browser-context-set-default-timeout) or [page.setDefaultTimeout()](/docs/api/class-page#page-set-default-timeout) methods.
* `type` "png" | "jpeg" _(optional)_[#](#page-screenshot-option-type)
Specify screenshot type, defaults to `png`.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Buffer](https://nodejs.org/api/buffer.html#buffer_class_buffer "Buffer")\>[#](#page-screenshot-return)
* * *
### setContent[](#page-set-content "Direct link to setContent")
Added before v1.9 page.setContent
This method internally calls [document.write()](https://developer.mozilla.org/en-US/docs/Web/API/Document/write), inheriting all its specific characteristics and behaviors.
**Usage**
await page.setContent(html);await page.setContent(html, options);
**Arguments**
* `html` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")[#](#page-set-content-option-html)
HTML markup to assign to the page.
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `timeout` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-set-content-option-timeout)
Maximum operation time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via `navigationTimeout` option in the config, or by using the [browserContext.setDefaultNavigationTimeout()](/docs/api/class-browsercontext#browser-context-set-default-navigation-timeout), [browserContext.setDefaultTimeout()](/docs/api/class-browsercontext#browser-context-set-default-timeout), [page.setDefaultNavigationTimeout()](/docs/api/class-page#page-set-default-navigation-timeout) or [page.setDefaultTimeout()](/docs/api/class-page#page-set-default-timeout) methods.
* `waitUntil` "load" | "domcontentloaded" | "networkidle" | "commit" _(optional)_[#](#page-set-content-option-wait-until)
When to consider operation succeeded, defaults to `load`. Events can be either:
* `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
* `'load'` - consider operation to be finished when the `load` event is fired.
* `'networkidle'` - **DISCOURAGED** consider operation to be finished when there are no network connections for at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
* `'commit'` - consider operation to be finished when network response is received and the document started loading.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[void](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined "void")\>[#](#page-set-content-return)
* * *
### setDefaultNavigationTimeout[](#page-set-default-navigation-timeout "Direct link to setDefaultNavigationTimeout")
Added before v1.9 page.setDefaultNavigationTimeout
This setting will change the default maximum navigation time for the following methods and related shortcuts:
* [page.goBack()](/docs/api/class-page#page-go-back)
* [page.goForward()](/docs/api/class-page#page-go-forward)
* [page.goto()](/docs/api/class-page#page-goto)
* [page.reload()](/docs/api/class-page#page-reload)
* [page.setContent()](/docs/api/class-page#page-set-content)
* [page.waitForNavigation()](/docs/api/class-page#page-wait-for-navigation)
* [page.waitForURL()](/docs/api/class-page#page-wait-for-url)
note
[page.setDefaultNavigationTimeout()](/docs/api/class-page#page-set-default-navigation-timeout) takes priority over [page.setDefaultTimeout()](/docs/api/class-page#page-set-default-timeout), [browserContext.setDefaultTimeout()](/docs/api/class-browsercontext#browser-context-set-default-timeout) and [browserContext.setDefaultNavigationTimeout()](/docs/api/class-browsercontext#browser-context-set-default-navigation-timeout).
**Usage**
page.setDefaultNavigationTimeout(timeout);
**Arguments**
* `timeout` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")[#](#page-set-default-navigation-timeout-option-timeout)
Maximum navigation time in milliseconds
* * *
### setDefaultTimeout[](#page-set-default-timeout "Direct link to setDefaultTimeout")
Added before v1.9 page.setDefaultTimeout
This setting will change the default maximum time for all the methods accepting [timeout](/docs/api/class-page#page-set-default-timeout-option-timeout) option.
note
[page.setDefaultNavigationTimeout()](/docs/api/class-page#page-set-default-navigation-timeout) takes priority over [page.setDefaultTimeout()](/docs/api/class-page#page-set-default-timeout).
**Usage**
page.setDefaultTimeout(timeout);
**Arguments**
* `timeout` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")[#](#page-set-default-timeout-option-timeout)
Maximum time in milliseconds. Pass `0` to disable timeout.
* * *
### setExtraHTTPHeaders[](#page-set-extra-http-headers "Direct link to setExtraHTTPHeaders")
Added before v1.9 page.setExtraHTTPHeaders
The extra HTTP headers will be sent with every request the page initiates.
note
[page.setExtraHTTPHeaders()](/docs/api/class-page#page-set-extra-http-headers) does not guarantee the order of headers in the outgoing requests.
**Usage**
await page.setExtraHTTPHeaders(headers);
**Arguments**
* `headers` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string"), [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")\>[#](#page-set-extra-http-headers-option-headers)
An object containing additional HTTP headers to be sent with every request. All header values must be strings.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[void](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined "void")\>[#](#page-set-extra-http-headers-return)
* * *
### setViewportSize[](#page-set-viewport-size "Direct link to setViewportSize")
Added before v1.9 page.setViewportSize
In the case of multiple pages in a single browser, each page can have its own viewport size. However, [browser.newContext()](/docs/api/class-browser#browser-new-context) allows to set viewport size (and more) for all pages in the context at once.
[page.setViewportSize()](/docs/api/class-page#page-set-viewport-size) will resize the page. A lot of websites don't expect phones to change size, so you should set the viewport size before navigating to the page. [page.setViewportSize()](/docs/api/class-page#page-set-viewport-size) will also reset `screen` size, use [browser.newContext()](/docs/api/class-browser#browser-new-context) with `screen` and `viewport` parameters if you need better control of these properties.
**Usage**
const page = await browser.newPage();await page.setViewportSize({ width: 640, height: 480,});await page.goto('https://example.com');
**Arguments**
* `viewportSize` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")[#](#page-set-viewport-size-option-viewport-size)
* `width` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")
page width in pixels.
* `height` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")
page height in pixels.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[void](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined "void")\>[#](#page-set-viewport-size-return)
* * *
### title[](#page-title "Direct link to title")
Added before v1.9 page.title
Returns the page's title.
**Usage**
await page.title();
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")\>[#](#page-title-return)
* * *
### unroute[](#page-unroute "Direct link to unroute")
Added before v1.9 page.unroute
Removes a route created with [page.route()](/docs/api/class-page#page-route). When [handler](/docs/api/class-page#page-unroute-option-handler) is not specified, removes all routes for the [url](/docs/api/class-page#page-unroute-option-url).
**Usage**
await page.unroute(url);await page.unroute(url, handler);
**Arguments**
* `url` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") | [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp "RegExp") | [function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([URL](https://nodejs.org/api/url.html "URL")):[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")[#](#page-unroute-option-url)
A glob pattern, regex pattern or predicate receiving [URL](https://nodejs.org/api/url.html "URL") to match while routing.
* `handler` [function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([Route](/docs/api/class-route "Route"), [Request](/docs/api/class-request "Request")):[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")\> | [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_[#](#page-unroute-option-handler)
Optional handler function to route the request.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[void](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined "void")\>[#](#page-unroute-return)
* * *
### unrouteAll[](#page-unroute-all "Direct link to unrouteAll")
Added in: v1.41 page.unrouteAll
Removes all routes created with [page.route()](/docs/api/class-page#page-route) and [page.routeFromHAR()](/docs/api/class-page#page-route-from-har).
**Usage**
await page.unrouteAll();await page.unrouteAll(options);
**Arguments**
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `behavior` "wait" | "ignoreErrors" | "default" _(optional)_[#](#page-unroute-all-option-behavior)
Specifies whether to wait for already running handlers and what to do if they throw errors:
* `'default'` - do not wait for current handler calls (if any) to finish, if unrouted handler throws, it may result in unhandled error
* `'wait'` - wait for current handler calls (if any) to finish
* `'ignoreErrors'` - do not wait for current handler calls (if any) to finish, all errors thrown by the handlers after unrouting are silently caught
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[void](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined "void")\>[#](#page-unroute-all-return)
* * *
### url[](#page-url "Direct link to url")
Added before v1.9 page.url
**Usage**
page.url();
**Returns**
* [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")[#](#page-url-return)
* * *
### video[](#page-video "Direct link to video")
Added before v1.9 page.video
Video object associated with this page.
**Usage**
page.video();
**Returns**
* [null](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null "null") | [Video](/docs/api/class-video "Video")[#](#page-video-return)
* * *
### viewportSize[](#page-viewport-size "Direct link to viewportSize")
Added before v1.9 page.viewportSize
**Usage**
page.viewportSize();
**Returns**
* [null](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null "null") | [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")[#](#page-viewport-size-return)
* `width` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")
page width in pixels.
* `height` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")
page height in pixels.
* * *
### waitForEvent[](#page-wait-for-event "Direct link to waitForEvent")
Added before v1.9 page.waitForEvent
Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy value. Will throw an error if the page is closed before the event is fired. Returns the event data value.
**Usage**
// Start waiting for download before clicking. Note no await.const downloadPromise = page.waitForEvent('download');await page.getByText('Download file').click();const download = await downloadPromise;
**Arguments**
* `event` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")[#](#page-wait-for-event-option-event)
Event name, same one typically passed into `*.on(event)`.
* `optionsOrPredicate` [function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function") | [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_[#](#page-wait-for-event-option-options-or-predicate)
* `predicate` [function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")
Receives the event data and resolves to truthy value when the waiting should resolve.
* `timeout` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_
Maximum time to wait for in milliseconds. Defaults to `0` - no timeout. The default value can be changed via `actionTimeout` option in the config, or by using the [browserContext.setDefaultTimeout()](/docs/api/class-browsercontext#browser-context-set-default-timeout) or [page.setDefaultTimeout()](/docs/api/class-page#page-set-default-timeout) methods.
Either a predicate that receives an event or an options object. Optional.
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `predicate` [function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function") _(optional)_[#](#page-wait-for-event-option-predicate)
Receives the event data and resolves to truthy value when the waiting should resolve.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")\>[#](#page-wait-for-event-return)
* * *
### waitForFunction[](#page-wait-for-function "Direct link to waitForFunction")
Added before v1.9 page.waitForFunction
Returns when the [pageFunction](/docs/api/class-page#page-wait-for-function-option-expression) returns a truthy value. It resolves to a JSHandle of the truthy value.
**Usage**
The [page.waitForFunction()](/docs/api/class-page#page-wait-for-function) can be used to observe viewport size change:
const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.(async () => { const browser = await webkit.launch(); const page = await browser.newPage(); const watchDog = page.waitForFunction(() => window.innerWidth < 100); await page.setViewportSize({ width: 50, height: 50 }); await watchDog; await browser.close();})();
To pass an argument to the predicate of [page.waitForFunction()](/docs/api/class-page#page-wait-for-function) function:
const selector = '.foo';await page.waitForFunction(selector => !!document.querySelector(selector), selector);
**Arguments**
* `pageFunction` [function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function") | [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")[#](#page-wait-for-function-option-expression)
Function to be evaluated in the page context.
* `arg` [EvaluationArgument](/docs/evaluating#evaluation-argument "EvaluationArgument") _(optional)_[#](#page-wait-for-function-option-arg)
Optional argument to pass to [pageFunction](/docs/api/class-page#page-wait-for-function-option-expression).
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `polling` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") | "raf" _(optional)_[#](#page-wait-for-function-option-polling)
If [polling](/docs/api/class-page#page-wait-for-function-option-polling) is `'raf'`, then [pageFunction](/docs/api/class-page#page-wait-for-function-option-expression) is constantly executed in `requestAnimationFrame` callback. If [polling](/docs/api/class-page#page-wait-for-function-option-polling) is a number, then it is treated as an interval in milliseconds at which the function would be executed. Defaults to `raf`.
* `timeout` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-wait-for-function-option-timeout)
Maximum time to wait for in milliseconds. Defaults to `0` - no timeout. The default value can be changed via `actionTimeout` option in the config, or by using the [browserContext.setDefaultTimeout()](/docs/api/class-browsercontext#browser-context-set-default-timeout) or [page.setDefaultTimeout()](/docs/api/class-page#page-set-default-timeout) methods.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[JSHandle](/docs/api/class-jshandle "JSHandle")\>[#](#page-wait-for-function-return)
* * *
### waitForLoadState[](#page-wait-for-load-state "Direct link to waitForLoadState")
Added before v1.9 page.waitForLoadState
Returns when the required load state has been reached.
This resolves when the page reaches a required load state, `load` by default. The navigation must have been committed when this method is called. If current document has already reached the required state, resolves immediately.
note
Most of the time, this method is not needed because Playwright [auto-waits before every action](/docs/actionability).
**Usage**
await page.getByRole('button').click(); // Click triggers navigation.await page.waitForLoadState(); // The promise resolves after 'load' event.
const popupPromise = page.waitForEvent('popup');await page.getByRole('button').click(); // Click triggers a popup.const popup = await popupPromise;await popup.waitForLoadState('domcontentloaded'); // Wait for the 'DOMContentLoaded' event.console.log(await popup.title()); // Popup is ready to use.
**Arguments**
* `state` "load" | "domcontentloaded" | "networkidle" _(optional)_[#](#page-wait-for-load-state-option-state)
Optional load state to wait for, defaults to `load`. If the state has been already reached while loading current document, the method resolves immediately. Can be one of:
* `'load'` - wait for the `load` event to be fired.
* `'domcontentloaded'` - wait for the `DOMContentLoaded` event to be fired.
* `'networkidle'` - **DISCOURAGED** wait until there are no network connections for at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `timeout` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-wait-for-load-state-option-timeout)
Maximum operation time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via `navigationTimeout` option in the config, or by using the [browserContext.setDefaultNavigationTimeout()](/docs/api/class-browsercontext#browser-context-set-default-navigation-timeout), [browserContext.setDefaultTimeout()](/docs/api/class-browsercontext#browser-context-set-default-timeout), [page.setDefaultNavigationTimeout()](/docs/api/class-page#page-set-default-navigation-timeout) or [page.setDefaultTimeout()](/docs/api/class-page#page-set-default-timeout) methods.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[void](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined "void")\>[#](#page-wait-for-load-state-return)
* * *
### waitForRequest[](#page-wait-for-request "Direct link to waitForRequest")
Added before v1.9 page.waitForRequest
Waits for the matching request and returns it. See [waiting for event](/docs/events#waiting-for-event) for more details about events.
**Usage**
// Start waiting for request before clicking. Note no await.const requestPromise = page.waitForRequest('https://example.com/resource');await page.getByText('trigger request').click();const request = await requestPromise;// Alternative way with a predicate. Note no await.const requestPromise = page.waitForRequest(request => request.url() === 'https://example.com' && request.method() === 'GET',);await page.getByText('trigger request').click();const request = await requestPromise;
**Arguments**
* `urlOrPredicate` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") | [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp "RegExp") | [function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([Request](/docs/api/class-request "Request")):[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") | [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")\>[#](#page-wait-for-request-option-url-or-predicate)
Request URL string, regex or predicate receiving [Request](/docs/api/class-request "Request") object.
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `timeout` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-wait-for-request-option-timeout)
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()](/docs/api/class-page#page-set-default-timeout) method.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Request](/docs/api/class-request "Request")\>[#](#page-wait-for-request-return)
* * *
### waitForResponse[](#page-wait-for-response "Direct link to waitForResponse")
Added before v1.9 page.waitForResponse
Returns the matched response. See [waiting for event](/docs/events#waiting-for-event) for more details about events.
**Usage**
// Start waiting for response before clicking. Note no await.const responsePromise = page.waitForResponse('https://example.com/resource');await page.getByText('trigger response').click();const response = await responsePromise;// Alternative way with a predicate. Note no await.const responsePromise = page.waitForResponse(response => response.url() === 'https://example.com' && response.status() === 200 && response.request().method() === 'GET');await page.getByText('trigger response').click();const response = await responsePromise;
**Arguments**
* `urlOrPredicate` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") | [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp "RegExp") | [function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([Response](/docs/api/class-response "Response")):[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") | [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")\>[#](#page-wait-for-response-option-url-or-predicate)
Request URL string, regex or predicate receiving [Response](/docs/api/class-response "Response") object. When a [baseURL](/docs/api/class-browser#browser-new-context-option-base-url) via the context options was provided and the passed URL is a path, it gets merged via the [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor.
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `timeout` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-wait-for-response-option-timeout)
Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can be changed by using the [browserContext.setDefaultTimeout()](/docs/api/class-browsercontext#browser-context-set-default-timeout) or [page.setDefaultTimeout()](/docs/api/class-page#page-set-default-timeout) methods.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Response](/docs/api/class-response "Response")\>[#](#page-wait-for-response-return)
* * *
### waitForURL[](#page-wait-for-url "Direct link to waitForURL")
Added in: v1.11 page.waitForURL
Waits for the main frame to navigate to the given URL.
**Usage**
await page.click('a.delayed-navigation'); // Clicking the link will indirectly cause a navigationawait page.waitForURL('**/target.html');
**Arguments**
* `url` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string") | [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp "RegExp") | [function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([URL](https://nodejs.org/api/url.html "URL")):[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")[#](#page-wait-for-url-option-url)
A glob pattern, regex pattern or predicate receiving [URL](https://nodejs.org/api/url.html "URL") to match while waiting for the navigation. Note that if the parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to the string.
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `timeout` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-wait-for-url-option-timeout)
Maximum operation time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via `navigationTimeout` option in the config, or by using the [browserContext.setDefaultNavigationTimeout()](/docs/api/class-browsercontext#browser-context-set-default-navigation-timeout), [browserContext.setDefaultTimeout()](/docs/api/class-browsercontext#browser-context-set-default-timeout), [page.setDefaultNavigationTimeout()](/docs/api/class-page#page-set-default-navigation-timeout) or [page.setDefaultTimeout()](/docs/api/class-page#page-set-default-timeout) methods.
* `waitUntil` "load" | "domcontentloaded" | "networkidle" | "commit" _(optional)_[#](#page-wait-for-url-option-wait-until)
When to consider operation succeeded, defaults to `load`. Events can be either:
* `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
* `'load'` - consider operation to be finished when the `load` event is fired.
* `'networkidle'` - **DISCOURAGED** consider operation to be finished when there are no network connections for at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
* `'commit'` - consider operation to be finished when network response is received and the document started loading.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[void](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined "void")\>[#](#page-wait-for-url-return)
* * *
### workers[](#page-workers "Direct link to workers")
Added before v1.9 page.workers
This method returns all of the dedicated [WebWorkers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) associated with the page.
note
This does not contain ServiceWorkers
**Usage**
page.workers();
**Returns**
* [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Worker](/docs/api/class-worker "Worker")\>[#](#page-workers-return)
* * *
Properties[](#properties "Direct link to Properties")
------------------------------------------------------
### clock[](#page-clock "Direct link to clock")
Added in: v1.45 page.clock
Playwright has ability to mock clock and passage of time.
**Usage**
page.clock
**Type**
* [Clock](/docs/api/class-clock "Clock")
* * *
### coverage[](#page-coverage "Direct link to coverage")
Added before v1.9 page.coverage
note
Only available for Chromium atm.
Browser-specific Coverage implementation. See [Coverage](/docs/api/class-coverage) for more details.
**Usage**
page.coverage
**Type**
* [Coverage](/docs/api/class-coverage "Coverage")
* * *
### keyboard[](#page-keyboard "Direct link to keyboard")
Added before v1.9 page.keyboard
**Usage**
page.keyboard
**Type**
* [Keyboard](/docs/api/class-keyboard "Keyboard")
* * *
### mouse[](#page-mouse "Direct link to mouse")
Added before v1.9 page.mouse
**Usage**
page.mouse
**Type**
* [Mouse](/docs/api/class-mouse "Mouse")
* * *
### request[](#page-request "Direct link to request")
Added in: v1.16 page.request
API testing helper associated with this page. This method returns the same instance as [browserContext.request](/docs/api/class-browsercontext#browser-context-request) on the page's context. See [browserContext.request](/docs/api/class-browsercontext#browser-context-request) for more details.
**Usage**
page.request
**Type**
* [APIRequestContext](/docs/api/class-apirequestcontext "APIRequestContext")
* * *
### touchscreen[](#page-touchscreen "Direct link to touchscreen")
Added before v1.9 page.touchscreen
**Usage**
page.touchscreen
**Type**
* [Touchscreen](/docs/api/class-touchscreen "Touchscreen")
* * *
Events[](#events "Direct link to Events")
------------------------------------------
### on('close')[](#page-event-close "Direct link to on('close')")
Added before v1.9 page.on('close')
Emitted when the page closes.
**Usage**
page.on('close', data => {});
**Event data**
* [Page](/docs/api/class-page "Page")
* * *
### on('console')[](#page-event-console "Direct link to on('console')")
Added before v1.9 page.on('console')
Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`.
The arguments passed into `console.log` are available on the [ConsoleMessage](/docs/api/class-consolemessage "ConsoleMessage") event handler argument.
**Usage**
page.on('console', async msg => { const values = []; for (const arg of msg.args()) values.push(await arg.jsonValue()); console.log(...values);});await page.evaluate(() => console.log('hello', 5, { foo: 'bar' }));
**Event data**
* [ConsoleMessage](/docs/api/class-consolemessage "ConsoleMessage")
* * *
### on('crash')[](#page-event-crash "Direct link to on('crash')")
Added before v1.9 page.on('crash')
Emitted when the page crashes. Browser pages might crash if they try to allocate too much memory. When the page crashes, ongoing and subsequent operations will throw.
The most common way to deal with crashes is to catch an exception:
try { // Crash might happen during a click. await page.click('button'); // Or while waiting for an event. await page.waitForEvent('popup');} catch (e) { // When the page crashes, exception message contains 'crash'.}
**Usage**
page.on('crash', data => {});
**Event data**
* [Page](/docs/api/class-page "Page")
* * *
### on('dialog')[](#page-event-dialog "Direct link to on('dialog')")
Added before v1.9 page.on('dialog')
Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Listener **must** either [dialog.accept()](/docs/api/class-dialog#dialog-accept) or [dialog.dismiss()](/docs/api/class-dialog#dialog-dismiss) the dialog - otherwise the page will [freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking) waiting for the dialog, and actions like click will never finish.
**Usage**
page.on('dialog', dialog => dialog.accept());
note
When no [page.on('dialog')](/docs/api/class-page#page-event-dialog) or [browserContext.on('dialog')](/docs/api/class-browsercontext#browser-context-event-dialog) listeners are present, all dialogs are automatically dismissed.
**Event data**
* [Dialog](/docs/api/class-dialog "Dialog")
* * *
### on('domcontentloaded')[](#page-event-dom-content-loaded "Direct link to on('domcontentloaded')")
Added in: v1.9 page.on('domcontentloaded')
Emitted when the JavaScript [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded) event is dispatched.
**Usage**
page.on('domcontentloaded', data => {});
**Event data**
* [Page](/docs/api/class-page "Page")
* * *
### on('download')[](#page-event-download "Direct link to on('download')")
Added before v1.9 page.on('download')
Emitted when attachment download started. User can access basic file operations on downloaded content via the passed [Download](/docs/api/class-download "Download") instance.
**Usage**
page.on('download', data => {});
**Event data**
* [Download](/docs/api/class-download "Download")
* * *
### on('filechooser')[](#page-event-file-chooser "Direct link to on('filechooser')")
Added in: v1.9 page.on('filechooser')
Emitted when a file chooser is supposed to appear, such as after clicking the `
`. Playwright can respond to it via setting the input files using [fileChooser.setFiles()](/docs/api/class-filechooser#file-chooser-set-files) that can be uploaded after that.
page.on('filechooser', async fileChooser => { await fileChooser.setFiles(path.join(__dirname, '/tmp/myfile.pdf'));});
**Usage**
page.on('filechooser', data => {});
**Event data**
* [FileChooser](/docs/api/class-filechooser "FileChooser")
* * *
### on('frameattached')[](#page-event-frame-attached "Direct link to on('frameattached')")
Added in: v1.9 page.on('frameattached')
Emitted when a frame is attached.
**Usage**
page.on('frameattached', data => {});
**Event data**
* [Frame](/docs/api/class-frame "Frame")
* * *
### on('framedetached')[](#page-event-frame-detached "Direct link to on('framedetached')")
Added in: v1.9 page.on('framedetached')
Emitted when a frame is detached.
**Usage**
page.on('framedetached', data => {});
**Event data**
* [Frame](/docs/api/class-frame "Frame")
* * *
### on('framenavigated')[](#page-event-frame-navigated "Direct link to on('framenavigated')")
Added in: v1.9 page.on('framenavigated')
Emitted when a frame is navigated to a new url.
**Usage**
page.on('framenavigated', data => {});
**Event data**
* [Frame](/docs/api/class-frame "Frame")
* * *
### on('load')[](#page-event-load "Direct link to on('load')")
Added before v1.9 page.on('load')
Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched.
**Usage**
page.on('load', data => {});
**Event data**
* [Page](/docs/api/class-page "Page")
* * *
### on('pageerror')[](#page-event-page-error "Direct link to on('pageerror')")
Added in: v1.9 page.on('pageerror')
Emitted when an uncaught exception happens within the page.
// Log all uncaught errors to the terminalpage.on('pageerror', exception => { console.log(`Uncaught exception: "${exception}"`);});// Navigate to a page with an exception.await page.goto('data:text/html,');
**Usage**
page.on('pageerror', data => {});
**Event data**
* [Error](https://nodejs.org/api/errors.html#errors_class_error "Error")
* * *
### on('popup')[](#page-event-popup "Direct link to on('popup')")
Added before v1.9 page.on('popup')
Emitted when the page opens a new tab or window. This event is emitted in addition to the [browserContext.on('page')](/docs/api/class-browsercontext#browser-context-event-page), but only for popups relevant to this page.
The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a popup with `window.open('http://example.com')`, this event will fire when the network request to "[http://example.com](http://example.com)" is done and its response has started loading in the popup. If you would like to route/listen to this network request, use [browserContext.route()](/docs/api/class-browsercontext#browser-context-route) and [browserContext.on('request')](/docs/api/class-browsercontext#browser-context-event-request) respectively instead of similar methods on the [Page](/docs/api/class-page "Page").
// Start waiting for popup before clicking. Note no await.const popupPromise = page.waitForEvent('popup');await page.getByText('open the popup').click();const popup = await popupPromise;console.log(await popup.evaluate('location.href'));
note
Use [page.waitForLoadState()](/docs/api/class-page#page-wait-for-load-state) to wait until the page gets to a particular state (you should not need it in most cases).
**Usage**
page.on('popup', data => {});
**Event data**
* [Page](/docs/api/class-page "Page")
* * *
### on('request')[](#page-event-request "Direct link to on('request')")
Added before v1.9 page.on('request')
Emitted when a page issues a request. The [request](/docs/api/class-request "Request") object is read-only. In order to intercept and mutate requests, see [page.route()](/docs/api/class-page#page-route) or [browserContext.route()](/docs/api/class-browsercontext#browser-context-route).
**Usage**
page.on('request', data => {});
**Event data**
* [Request](/docs/api/class-request "Request")
* * *
### on('requestfailed')[](#page-event-request-failed "Direct link to on('requestfailed')")
Added in: v1.9 page.on('requestfailed')
Emitted when a request fails, for example by timing out.
page.on('requestfailed', request => { console.log(request.url() + ' ' + request.failure().errorText);});
note
HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete with [page.on('requestfinished')](/docs/api/class-page#page-event-request-finished) event and not with [page.on('requestfailed')](/docs/api/class-page#page-event-request-failed). A request will only be considered failed when the client cannot get an HTTP response from the server, e.g. due to network error net::ERR\_FAILED.
**Usage**
page.on('requestfailed', data => {});
**Event data**
* [Request](/docs/api/class-request "Request")
* * *
### on('requestfinished')[](#page-event-request-finished "Direct link to on('requestfinished')")
Added in: v1.9 page.on('requestfinished')
Emitted when a request finishes successfully after downloading the response body. For a successful response, the sequence of events is `request`, `response` and `requestfinished`.
**Usage**
page.on('requestfinished', data => {});
**Event data**
* [Request](/docs/api/class-request "Request")
* * *
### on('response')[](#page-event-response "Direct link to on('response')")
Added before v1.9 page.on('response')
Emitted when [response](/docs/api/class-response "Response") status and headers are received for a request. For a successful response, the sequence of events is `request`, `response` and `requestfinished`.
**Usage**
page.on('response', data => {});
**Event data**
* [Response](/docs/api/class-response "Response")
* * *
### on('websocket')[](#page-event-web-socket "Direct link to on('websocket')")
Added in: v1.9 page.on('websocket')
Emitted when [WebSocket](/docs/api/class-websocket "WebSocket") request is sent.
**Usage**
page.on('websocket', data => {});
**Event data**
* [WebSocket](/docs/api/class-websocket "WebSocket")
* * *
### on('worker')[](#page-event-worker "Direct link to on('worker')")
Added before v1.9 page.on('worker')
Emitted when a dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is spawned by the page.
**Usage**
page.on('worker', data => {});
**Event data**
* [Worker](/docs/api/class-worker "Worker")
* * *
Deprecated[](#deprecated "Direct link to Deprecated")
------------------------------------------------------
### $[](#page-query-selector "Direct link to $")
Added in: v1.9 page.$
Discouraged
Use locator-based [page.locator()](/docs/api/class-page#page-locator) instead. Read more about [locators](/docs/locators).
The method finds an element matching the specified selector within the page. If no elements match the selector, the return value resolves to `null`. To wait for an element on the page, use [locator.waitFor()](/docs/api/class-locator#locator-wait-for).
**Usage**
await page.$(selector);await page.$(selector, options);
**Arguments**
* `selector` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")[#](#page-query-selector-option-selector)
A selector to query for.
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `strict` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_ Added in: v1.14[#](#page-query-selector-option-strict)
When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call throws an exception.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[null](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null "null") | [ElementHandle](/docs/api/class-elementhandle "ElementHandle")\>[#](#page-query-selector-return)
* * *
### $$[](#page-query-selector-all "Direct link to $$")
Added in: v1.9 page.$$
Discouraged
Use locator-based [page.locator()](/docs/api/class-page#page-locator) instead. Read more about [locators](/docs/locators).
The method finds all elements matching the specified selector within the page. If no elements match the selector, the return value resolves to `[]`.
**Usage**
await page.$$(selector);
**Arguments**
* `selector` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")[#](#page-query-selector-all-option-selector)
A selector to query for.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[ElementHandle](/docs/api/class-elementhandle "ElementHandle")\>>[#](#page-query-selector-all-return)
* * *
### $eval[](#page-eval-on-selector "Direct link to $eval")
Added in: v1.9 page.$eval
Discouraged
This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests. Use [locator.evaluate()](/docs/api/class-locator#locator-evaluate), other [Locator](/docs/api/class-locator "Locator") helper methods or web-first assertions instead.
The method finds an element matching the specified selector within the page and passes it as a first argument to [pageFunction](/docs/api/class-page#page-eval-on-selector-option-expression). If no elements match the selector, the method throws an error. Returns the value of [pageFunction](/docs/api/class-page#page-eval-on-selector-option-expression).
If [pageFunction](/docs/api/class-page#page-eval-on-selector-option-expression) returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then [page.$eval()](/docs/api/class-page#page-eval-on-selector) would wait for the promise to resolve and return its value.
**Usage**
const searchValue = await page.$eval('#search', el => el.value);const preloadHref = await page.$eval('link[rel=preload]', el => el.href);const html = await page.$eval('.main-container', (e, suffix) => e.outerHTML + suffix, 'hello');// In TypeScript, this example requires an explicit type annotation (HTMLLinkElement) on el:const preloadHrefTS = await page.$eval('link[rel=preload]', (el: HTMLLinkElement) => el.href);
**Arguments**
* `selector` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")[#](#page-eval-on-selector-option-selector)
A selector to query for.
* `pageFunction` [function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([Element](https://developer.mozilla.org/en-US/docs/Web/API/element "Element")) | [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")[#](#page-eval-on-selector-option-expression)
Function to be evaluated in the page context.
* `arg` [EvaluationArgument](/docs/evaluating#evaluation-argument "EvaluationArgument") _(optional)_[#](#page-eval-on-selector-option-arg)
Optional argument to pass to [pageFunction](/docs/api/class-page#page-eval-on-selector-option-expression).
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `strict` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_ Added in: v1.14[#](#page-eval-on-selector-option-strict)
When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call throws an exception.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")\>[#](#page-eval-on-selector-return)
* * *
### $$eval[](#page-eval-on-selector-all "Direct link to $$eval")
Added in: v1.9 page.$$eval
Discouraged
In most cases, [locator.evaluateAll()](/docs/api/class-locator#locator-evaluate-all), other [Locator](/docs/api/class-locator "Locator") helper methods and web-first assertions do a better job.
The method finds all elements matching the specified selector within the page and passes an array of matched elements as a first argument to [pageFunction](/docs/api/class-page#page-eval-on-selector-all-option-expression). Returns the result of [pageFunction](/docs/api/class-page#page-eval-on-selector-all-option-expression) invocation.
If [pageFunction](/docs/api/class-page#page-eval-on-selector-all-option-expression) returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then [page.$$eval()](/docs/api/class-page#page-eval-on-selector-all) would wait for the promise to resolve and return its value.
**Usage**
const divCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 10);
**Arguments**
* `selector` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")[#](#page-eval-on-selector-all-option-selector)
A selector to query for.
* `pageFunction` [function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[Element](https://developer.mozilla.org/en-US/docs/Web/API/element "Element")\>) | [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")[#](#page-eval-on-selector-all-option-expression)
Function to be evaluated in the page context.
* `arg` [EvaluationArgument](/docs/evaluating#evaluation-argument "EvaluationArgument") _(optional)_[#](#page-eval-on-selector-all-option-arg)
Optional argument to pass to [pageFunction](/docs/api/class-page#page-eval-on-selector-all-option-expression).
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")\>[#](#page-eval-on-selector-all-return)
* * *
### accessibility[](#page-accessibility "Direct link to accessibility")
Added before v1.9 page.accessibility
Deprecated
This property is discouraged. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you need to test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for integration with Axe.
**Usage**
page.accessibility
**Type**
* [Accessibility](/docs/api/class-accessibility "Accessibility")
* * *
### check[](#page-check "Direct link to check")
Added before v1.9 page.check
Discouraged
Use locator-based [locator.check()](/docs/api/class-locator#locator-check) instead. Read more about [locators](/docs/locators).
This method checks an element matching [selector](/docs/api/class-page#page-check-option-selector) by performing the following steps:
1. Find an element matching [selector](/docs/api/class-page#page-check-option-selector). If there is none, wait until a matching element is attached to the DOM.
2. Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is already checked, this method returns immediately.
3. Wait for [actionability](/docs/actionability) checks on the matched element, unless [force](/docs/api/class-page#page-check-option-force) option is set. If the element is detached during the checks, the whole action is retried.
4. Scroll the element into view if needed.
5. Use [page.mouse](/docs/api/class-page#page-mouse) to click in the center of the element.
6. Ensure that the element is now checked. If not, this method throws.
When all steps combined have not finished during the specified [timeout](/docs/api/class-page#page-check-option-timeout), this method throws a [TimeoutError](/docs/api/class-timeouterror "TimeoutError"). Passing zero timeout disables this.
**Usage**
await page.check(selector);await page.check(selector, options);
**Arguments**
* `selector` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")[#](#page-check-option-selector)
A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `force` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_[#](#page-check-option-force)
Whether to bypass the [actionability](/docs/actionability) checks. Defaults to `false`.
* `noWaitAfter` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_[#](#page-check-option-no-wait-after)
Deprecated
This option has no effect.
This option has no effect.
* `position` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_ Added in: v1.11[#](#page-check-option-position)
* `x` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")
* `y` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")
A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.
* `strict` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_ Added in: v1.14[#](#page-check-option-strict)
When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call throws an exception.
* `timeout` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-check-option-timeout)
Maximum time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via `actionTimeout` option in the config, or by using the [browserContext.setDefaultTimeout()](/docs/api/class-browsercontext#browser-context-set-default-timeout) or [page.setDefaultTimeout()](/docs/api/class-page#page-set-default-timeout) methods.
* `trial` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_ Added in: v1.11[#](#page-check-option-trial)
When set, this method only performs the [actionability](/docs/actionability) checks and skips the action. Defaults to `false`. Useful to wait until the element is ready for the action without performing it.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[void](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined "void")\>[#](#page-check-return)
* * *
### click[](#page-click "Direct link to click")
Added before v1.9 page.click
Discouraged
Use locator-based [locator.click()](/docs/api/class-locator#locator-click) instead. Read more about [locators](/docs/locators).
This method clicks an element matching [selector](/docs/api/class-page#page-click-option-selector) by performing the following steps:
1. Find an element matching [selector](/docs/api/class-page#page-click-option-selector). If there is none, wait until a matching element is attached to the DOM.
2. Wait for [actionability](/docs/actionability) checks on the matched element, unless [force](/docs/api/class-page#page-click-option-force) option is set. If the element is detached during the checks, the whole action is retried.
3. Scroll the element into view if needed.
4. Use [page.mouse](/docs/api/class-page#page-mouse) to click in the center of the element, or the specified [position](/docs/api/class-page#page-click-option-position).
5. Wait for initiated navigations to either succeed or fail, unless [noWaitAfter](/docs/api/class-page#page-click-option-no-wait-after) option is set.
When all steps combined have not finished during the specified [timeout](/docs/api/class-page#page-click-option-timeout), this method throws a [TimeoutError](/docs/api/class-timeouterror "TimeoutError"). Passing zero timeout disables this.
**Usage**
await page.click(selector);await page.click(selector, options);
**Arguments**
* `selector` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")[#](#page-click-option-selector)
A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `button` "left" | "right" | "middle" _(optional)_[#](#page-click-option-button)
Defaults to `left`.
* `clickCount` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-click-option-click-count)
defaults to 1. See [UIEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail").
* `delay` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-click-option-delay)
Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.
* `force` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_[#](#page-click-option-force)
Whether to bypass the [actionability](/docs/actionability) checks. Defaults to `false`.
* `modifiers` [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<"Alt" | "Control" | "ControlOrMeta" | "Meta" | "Shift"> _(optional)_[#](#page-click-option-modifiers)
Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to "Control" on Windows and Linux and to "Meta" on macOS.
* `noWaitAfter` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_[#](#page-click-option-no-wait-after)
Deprecated
This option will default to `true` in the future.
Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. Defaults to `false`.
* `position` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_[#](#page-click-option-position)
* `x` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")
* `y` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")
A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.
* `strict` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_ Added in: v1.14[#](#page-click-option-strict)
When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call throws an exception.
* `timeout` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-click-option-timeout)
Maximum time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via `actionTimeout` option in the config, or by using the [browserContext.setDefaultTimeout()](/docs/api/class-browsercontext#browser-context-set-default-timeout) or [page.setDefaultTimeout()](/docs/api/class-page#page-set-default-timeout) methods.
* `trial` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_ Added in: v1.11[#](#page-click-option-trial)
When set, this method only performs the [actionability](/docs/actionability) checks and skips the action. Defaults to `false`. Useful to wait until the element is ready for the action without performing it. Note that keyboard `modifiers` will be pressed regardless of `trial` to allow testing elements which are only visible when those keys are pressed.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[void](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined "void")\>[#](#page-click-return)
* * *
### dblclick[](#page-dblclick "Direct link to dblclick")
Added before v1.9 page.dblclick
Discouraged
Use locator-based [locator.dblclick()](/docs/api/class-locator#locator-dblclick) instead. Read more about [locators](/docs/locators).
This method double clicks an element matching [selector](/docs/api/class-page#page-dblclick-option-selector) by performing the following steps:
1. Find an element matching [selector](/docs/api/class-page#page-dblclick-option-selector). If there is none, wait until a matching element is attached to the DOM.
2. Wait for [actionability](/docs/actionability) checks on the matched element, unless [force](/docs/api/class-page#page-dblclick-option-force) option is set. If the element is detached during the checks, the whole action is retried.
3. Scroll the element into view if needed.
4. Use [page.mouse](/docs/api/class-page#page-mouse) to double click in the center of the element, or the specified [position](/docs/api/class-page#page-dblclick-option-position).
When all steps combined have not finished during the specified [timeout](/docs/api/class-page#page-dblclick-option-timeout), this method throws a [TimeoutError](/docs/api/class-timeouterror "TimeoutError"). Passing zero timeout disables this.
note
`page.dblclick()` dispatches two `click` events and a single `dblclick` event.
**Usage**
await page.dblclick(selector);await page.dblclick(selector, options);
**Arguments**
* `selector` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")[#](#page-dblclick-option-selector)
A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `button` "left" | "right" | "middle" _(optional)_[#](#page-dblclick-option-button)
Defaults to `left`.
* `delay` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-dblclick-option-delay)
Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.
* `force` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_[#](#page-dblclick-option-force)
Whether to bypass the [actionability](/docs/actionability) checks. Defaults to `false`.
* `modifiers` [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<"Alt" | "Control" | "ControlOrMeta" | "Meta" | "Shift"> _(optional)_[#](#page-dblclick-option-modifiers)
Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to "Control" on Windows and Linux and to "Meta" on macOS.
* `noWaitAfter` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_[#](#page-dblclick-option-no-wait-after)
Deprecated
This option has no effect.
This option has no effect.
* `position` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_[#](#page-dblclick-option-position)
* `x` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")
* `y` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")
A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.
* `strict` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_ Added in: v1.14[#](#page-dblclick-option-strict)
When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call throws an exception.
* `timeout` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-dblclick-option-timeout)
Maximum time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via `actionTimeout` option in the config, or by using the [browserContext.setDefaultTimeout()](/docs/api/class-browsercontext#browser-context-set-default-timeout) or [page.setDefaultTimeout()](/docs/api/class-page#page-set-default-timeout) methods.
* `trial` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_ Added in: v1.11[#](#page-dblclick-option-trial)
When set, this method only performs the [actionability](/docs/actionability) checks and skips the action. Defaults to `false`. Useful to wait until the element is ready for the action without performing it. Note that keyboard `modifiers` will be pressed regardless of `trial` to allow testing elements which are only visible when those keys are pressed.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[void](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined "void")\>[#](#page-dblclick-return)
* * *
### dispatchEvent[](#page-dispatch-event "Direct link to dispatchEvent")
Added before v1.9 page.dispatchEvent
Discouraged
Use locator-based [locator.dispatchEvent()](/docs/api/class-locator#locator-dispatch-event) instead. Read more about [locators](/docs/locators).
The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element, `click` is dispatched. This is equivalent to calling [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
**Usage**
await page.dispatchEvent('button#submit', 'click');
Under the hood, it creates an instance of an event based on the given [type](/docs/api/class-page#page-dispatch-event-option-type), initializes it with [eventInit](/docs/api/class-page#page-dispatch-event-option-event-init) properties and dispatches it on the element. Events are `composed`, `cancelable` and bubble by default.
Since [eventInit](/docs/api/class-page#page-dispatch-event-option-event-init) is event-specific, please refer to the events documentation for the lists of initial properties:
* [DeviceMotionEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent)
* [DeviceOrientationEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent)
* [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
* [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
* [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
* [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
* [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
* [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
* [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
* [WheelEvent](https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent)
You can also specify `JSHandle` as the property value if you want live objects to be passed into the event:
// Note you can only create DataTransfer in Chromium and Firefoxconst dataTransfer = await page.evaluateHandle(() => new DataTransfer());await page.dispatchEvent('#source', 'dragstart', { dataTransfer });
**Arguments**
* `selector` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")[#](#page-dispatch-event-option-selector)
A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
* `type` [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string")[#](#page-dispatch-event-option-type)
DOM event type: `"click"`, `"dragstart"`, etc.
* `eventInit` [EvaluationArgument](/docs/evaluating#evaluation-argument "EvaluationArgument") _(optional)_[#](#page-dispatch-event-option-event-init)
Optional event-specific initialization properties.
* `options` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object") _(optional)_
* `strict` [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean") _(optional)_ Added in: v1.14[#](#page-dispatch-event-option-strict)
When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call throws an exception.
* `timeout` [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number") _(optional)_[#](#page-dispatch-event-option-timeout)
Maximum time in milliseconds. Defaults to `0` - no timeout. The default value can be changed via `actionTimeout` option in the config, or by using the [browserContext.setDefaultTimeout()](/docs/api/class-browsercontext#browser-context-set-default-timeout) or [page.setDefaultTimeout()](/docs/api/class-page#page-set-default-timeout) methods.
**Returns**
* [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[void](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined "void")\>[#](#page-dispatch-event-return)
* * *
### fill[](#page-fill "Direct link to fill")
Added before v1.9 page.fill
Discouraged
Use locator-based [locator.fill()](/docs/api/class-locator#locator-fill) instead. Read more about [locators](/docs/locators).
This method waits for an element matching [selector](/docs/api/class-page#page-fill-option-selector), waits for [actionability](/docs/actionability) checks, focuses the element, fills it and triggers an `input` event after filling. Note that you can pass an empty string to clear the input field.
If the target element is not an `
`, `