List of all available devices is available in the source code: [DeviceDescriptors.js](https://github.com/GoogleChrome/puppeteer/blob/master/DeviceDescriptors.js).
-`options`<[Object]> Set of configurable options to set on the browser. Can have the following fields:
-`headless`<[boolean]> Wether to run chromium in headless mode. Defaults to `true`.
-`executablePath`<[string]> Path to a chromium executable to run instead of bundled chromium.
-`args`<[Array]<[string]>> Additional arguments to pass to the chromium instance. List of chromium flags could be found [here](http://peter.sh/experiments/chromium-command-line-switches/).
- returns: <[Promise]<[string]>> String describing browser version. For headless chromium, this is similar to `HeadlessChrome/61.0.3153.0`. For non-headless, this is `Chrome/61.0.3153.0`.
> **NOTE** the format of browser.version() is not fixed and might change with future releases of the library.
Page provides methods to interact with browser page. Page could be thought about as a browser tab, so one [Browser] instance might have multiple [Page] instances.
Emitted when a javascript dialog, such as `alert`, `prompt`, `confirm` or `beforeunload`, gets opened on the page. Puppeteer can take action to the dialog via dialog's [accept](#dialogacceptprompttext) or [dismiss](#dialogdismiss) methods.
#### event: 'frameattached'
-<[Frame]>
Emitted when a frame gets attached.
#### event: 'framedetached'
-<[Frame]>
Emitted when a frame gets detached.
#### event: 'framenavigated'
-<[Frame]>
Emitted when a frame committed navigation.
#### event: 'load'
Emitted when a page's `load` event was dispatched.
#### event: 'pageerror'
-<[string]>
Emitted when an unhandled exception happens on the page. The only argument of the event holds the exception message.
#### event: 'request'
-<[Request]>
Emitted when a page issues a request. The [request] object is a read-only object. In order to intercept and mutate requests, see [page.setRequestInterceptor](#pagesetrequestinterceptorinterceptor)
Adds a `<script></script>` tag to the page with the desired url. Alternatively, javascript could be injected to the page via [`page.injectFile`](#pageinjectfilefilepath) method.
-`selector`<[string]> A query [selector] to search for element to click. If there are multiple elements satisfying the selector, the first will be clicked.
- returns: <[Promise]> Promise which resolves when the element matching `selector` is successfully clicked. Promise gets rejected if there's no element matching `selector`.
Adds a function which would be invoked in one of the following scenarios:
- whenever the page gets navigated
- whenever the child frame gets attached or navigated. In this case, the function gets invoked in the context of the newly attached frame
The function is invoked after the document was created but before any of its scripts were run. This is useful to amend javascript environment, e.g. to seed [Math.random](https://github.com/GoogleChrome/puppeteer/blob/master/examples/unrandomize.js)
- returns: <[Promise]> Promise which resolves when the element matching `selector` is successfully focused. Promise gets rejected if there's no element matching `selector`.
-`options`<[Object]> Navigation parameters which might have the following properties:
-`timeout`<[number]> Maximum navigation time in milliseconds, defaults to 30 seconds.
-`waitUntil`<[string]> When to consider navigation succeeded, defaults to `load`. Could be either:
-`load` - consider navigation to be finished when the `load` event is fired.
-`networkidle` - consider navigation to be finished when the network activity stays "idle" for at least `networkIdleTimeout`ms.
-`networkIdleInflight`<[number]> Maximum amount of inflight requests which are considered "idle". Takes effect only with `waitUntil: 'networkidle'` parameter.
-`networkIdleTimeout`<[number]> A timeout to wait before completing navigation. Takes effect only with `waitUntil: 'networkidle'` parameter.
- returns: <[Promise]<[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. If
-`options`<[Object]> Navigation parameters which might have the following properties:
-`timeout`<[number]> Maximum navigation time in milliseconds, defaults to 30 seconds.
-`waitUntil`<[string]> When to consider navigation succeeded, defaults to `load`. Could be either:
-`load` - consider navigation to be finished when the `load` event is fired.
-`networkidle` - consider navigation to be finished when the network activity stays "idle" for at least `networkIdleTimeout`ms.
-`networkIdleInflight`<[number]> Maximum amount of inflight requests which are considered "idle". Takes effect only with `waitUntil: 'networkidle'` parameter.
-`networkIdleTimeout`<[number]> A timeout to wait before completing navigation. Takes effect only with `waitUntil: 'networkidle'` parameter.
- returns: <[Promise]<[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. If
-`selector`<[string]> A query [selector] to search for element to hover. If there are multiple elements satisfying the selector, the first will be hovered.
- returns: <[Promise]> Promise which resolves when the element matching `selector` is successfully hovered. Promise gets rejected if there's no element matching `selector`.
-`networkIdleInflight`<[number]> Maximum amount of inflight requests which are considered "idle". Takes effect only with `waitUntil: 'networkidle'` parameter.
-`networkIdleTimeout`<[number]> A timeout to wait before completing navigation. Takes effect only with `waitUntil: 'networkidle'` parameter.
- returns: <[Promise]<[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.
The `page.navigate` will throw an error if:
- there's an SSL error (e.g. in case of self-signed certificates).
-`options`<[Object]> Navigation parameters which might have the following properties:
-`timeout`<[number]> Maximum navigation time in milliseconds, defaults to 30 seconds.
-`waitUntil`<[string]> When to consider navigation succeeded, defaults to `load`. Could be either:
-`load` - consider navigation to be finished when the `load` event is fired.
-`networkidle` - consider navigation to be finished when the network activity stays "idle" for at least `networkIdleTimeout`ms.
-`networkIdleInflight`<[number]> Maximum amount of inflight requests which are considered "idle". Takes effect only with `waitUntil: 'networkidle'` parameter.
-`networkIdleTimeout`<[number]> A timeout to wait before completing navigation. Takes effect only with `waitUntil: 'networkidle'` parameter.
- returns: <[Promise]<[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.
- returns: <[Promise]> Promise which resolves when request interceptor is successfully installed on the page.
After the request interceptor is installed on the page, every request will be reported to the interceptor. The [InterceptedRequest] could be modified and then either continued via the `continue()` method, or aborted via the `abort()` method.
En example of a naive request interceptor which aborts all image requests:
> **NOTE** in certain cases, setting viewport will reload the page so that the `isMobile` or `hasTouch` options will be able to interfere in project loading.
The page's viewport size defines page's dimensions, observable from page via `window.innerWidth / window.innerHeight`. The viewport size defines a size of page
screenshot (unless a `fullPage` option is given).
In case of multiple pages in one browser, each page can have its own viewport size.
-`visible`<[boolean]> wait for element to be present in DOM and to be visible, i.e. to not have `display: none` or `visibility: hidden` CSS properties. Defaults to `false`.
-`timeout`<[number]> maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds).
- if `selectorOrTimeout` is a `string`, than the first argument is treated as a [selector] to wait for and the method is a shortcut for [frame.waitForSelector](#framewaitforselectorselector-options)
- if `selectorOrTimeout` is a `number`, than the first argument is treated as a timeout in milliseconds and the method returns a promise which resolves after the timeout
-`options`<[Object]> Navigation parameters which might have the following properties:
-`timeout`<[number]> Maximum navigation time in milliseconds, defaults to 30 seconds.
-`waitUntil`<[string]> When to consider navigation succeeded, defaults to `load`. Could be either:
-`load` - consider navigation to be finished when the `load` event is fired.
-`networkidle` - consider navigation to be finished when the network activity stays "idle" for at least `networkIdleTimeout`ms.
-`networkIdleInflight`<[number]> Maximum amount of inflight requests which are considered "idle". Takes effect only with `waitUntil: 'networkidle'` parameter.
-`networkIdleTimeout`<[number]> A timeout to wait before completing navigation. Takes effect only with `waitUntil: 'networkidle'` parameter.
- returns: <[Promise]<[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.
-`visible`<[boolean]> wait for element to be present in DOM and to be visible, i.e. to not have `display: none` or `visibility: hidden` CSS properties. Defaults to `false`.
-`timeout`<[number]> maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds).
Keyboard provides an api for managing a virtual keyboard. The high level api is [`page.type`](#pageypetext), which takes raw characters and generates proper keydown, keypress/input, and keyup events on your page.
For finer control, you can use [`keyboard.down`](#keyboarddownkey-options), [`keyboard.up`](#keyboardupkey), and [`keyboard.sendCharacter`](#keyboardsendcharacterchar) to manually fire events as if they were generated from a real keyboard.
If `key` is a modifier key, `Shift`, `Meta`, `Control`, or `Alt`, subsequent key presses will be sent with that modifier active. To release the modifier key, use [`keyboard.up`](#keyboardupkey).
At every point of time, page exposes its current frame tree via the [page.mainFrame()](#pagemainframe) and [frame.childFrames()](#framechildframes) methods.
[Frame] object's lifecycle is controlled by three events, dispatched on the page object:
- ['frameattached'](#event-frameattached) - fired when the frame gets attached to the page. Frame could be attached to the page only once.
- ['framenavigated'](#event-framenavigated) - fired when the frame commits navigation to a different URL.
- ['framedetached'](#event-framedetached) - fired when the frame gets detached from the page. Frame could be detached from the page only once.
- returns: <[Promise]> Promise which resolves as the script gets added and loads.
Adds a `<script></script>` tag to the frame with the desired url. Alternatively, javascript could be injected to the frame via [`frame.injectFile`](#frameinjectfilefilepath) method.
-`selector`<[string]> A query [selector] to search for element to click. If there are multiple elements satisfying the selector, the first will be clicked.
-`button`<[string]> `left`, `right`, or `middle`, defaults to `left`.
-`clickCount`<[number]> defaults to 1
- returns: <[Promise]> Promise which resolves when the element matching `selector` is successfully clicked. Promise gets rejected if there's no element matching `selector`.
If the function, passed to the `frame.evaluate`, returns a [Promise], then `frame.evaluate` would wait for the promise to resolve and return it's value.
- returns: <[Promise]> Promise which resolves when the element matching `selector` is successfully focused. Promise gets rejected if there's no element matching `selector`.
-`selector`<[string]> A query [selector] to search for element to hover. If there are multiple elements satisfying the selector, the first will be hovered.
- returns: <[Promise]> Promise which resolves when the element matching `selector` is successfully hovered. Promise gets rejected if there's no element matching `selector`.
-`visible`<[boolean]> wait for element to be present in DOM and to be visible, i.e. to not have `display: none` or `visibility: hidden` CSS properties. Defaults to `false`.
-`timeout`<[number]> maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds).
- if `selectorOrTimeout` is a `string`, than the first argument is treated as a [selector] to wait for and the method is a shortcut for [frame.waitForSelector](#framewaitforselectorselectoroptions)
- if `selectorOrTimeout` is a `number`, than the first argument is treated as a timeout in milliseconds and the method returns a promise which resolves after the timeout
-`visible`<[boolean]> wait for element to be present in DOM and to be visible, i.e. to not have `display: none` or `visibility: hidden` CSS properties. Defaults to `false`.
-`timeout`<[number]> maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds).
Whenever the page sends a request, the following events are emitted by puppeteer's page:
- ['request'](#event-request) emitted when the request is issued by the page.
- ['response'](#event-response) emitted when/if the response is received for the request.
- ['requestfinished'](#event-requestfinished) emitted when the response body is downloaded and the request is complete.
If request fails at some point, then instead of 'requestfinished' event (and possibly instead of 'response' event), the ['requestfailed'](#event-requestfailed) event is emitted.
If request gets a 'redirect' response, the request is successfully finished with the 'requestfinished' event, and a new request is issued to a redirected url.
[Request] class represents requests which are sent by page. [Request] implements [Body] mixin, which in case of HTTP POST requests allows clients to call `request.json()` or `request.text()` to get different representations of request's body.
[Response] class represents responses which are received by page. [Response] implements [Body] mixin, which allows clients to call `response.json()` or `response.text()` to get different representations of response body.
[InterceptedRequest] represents an intercepted request, which can be mutated and either continued or aborted. [InterceptedRequest] which is not continued or aborted will be in a 'hanging' state.