diff --git a/docs-src/api-body.md b/docs-src/api-body.md index 8b8f8c95af..f828a986f9 100644 --- a/docs-src/api-body.md +++ b/docs-src/api-body.md @@ -18,38 +18,31 @@ const { firefox } = require('playwright'); // Or 'chromium' or 'webkit'. ``` See [ChromiumBrowser], [FirefoxBrowser] and [WebKitBrowser] for browser-specific features. Note that -[browserType.connect(options)](#browsertypeconnectoptions) and +[browserType.connect(options)](#browsertypeconnect) and [browserType.launch([options])](#browsertypelaunchoptions) always return a specific browser instance, based on the browser being connected to or launched. -- [event: 'disconnected'](#event-disconnected) -- [browser.close()](#browserclose) -- [browser.contexts()](#browsercontexts) -- [browser.isConnected()](#browserisconnected) -- [browser.newContext([options])](#browsernewcontextoptions) -- [browser.newPage([options])](#browsernewpageoptions) -- [browser.version()](#browserversion) #### event: 'disconnected' Emitted when Browser gets disconnected from the browser application. This might happen because of one of the following: -- Browser application is closed or crashed. -- The [`browser.close`](#browserclose) method was called. +* Browser application is closed or crashed. +* The [`browser.close`](#browserclose) method was called. -#### browser.close() +#### browser.close - returns: <[Promise]> In case this browser is obtained using [browserType.launch](#browsertypelaunchoptions), closes the browser and all of its pages (if any were opened). -In case this browser is obtained using [browserType.connect](#browsertypeconnectoptions), clears all created contexts +In case this browser is obtained using [browserType.connect](#browsertypeconnect), clears all created contexts belonging to this browser and disconnects from the browser server. The [Browser] object itself is considered to be disposed and cannot be used anymore. -#### browser.contexts() +#### browser.contexts - returns: <[Array]<[BrowserContext]>> Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts. @@ -62,12 +55,12 @@ const context = await browser.newContext(); console.log(browser.contexts().length); // prints `1` ``` -#### browser.isConnected() +#### browser.isConnected - returns: <[boolean]> Indicates that the browser is connected. -#### browser.newContext([options]) +#### browser.newContext - `options` <[Object]> - %%-shared-context-params-%%-as-is - %%-context-option-proxy-%% @@ -87,7 +80,7 @@ Creates a new browser context. It won't share cookies/cache with other browser c })(); ``` -#### browser.newPage([options]) +#### browser.newPage - `options` <[Object]> - %%-shared-context-params-%%-as-is - %%-context-option-proxy-%% @@ -100,7 +93,7 @@ This is a convenience API that should only be used for the single-page scenarios testing frameworks should explicitly create [browser.newContext](#browsernewcontextoptions) followed by the [browserContext.newPage](#browsercontextnewpage) to control their exact life times. -#### browser.version() +#### browser.version - returns: <[string]> Returns the browser version. @@ -127,38 +120,14 @@ await context.close(); ``` -- [event: 'close'](#event-close) -- [event: 'page'](#event-page) -- [browserContext.addCookies(cookies)](#browsercontextaddcookiescookies) -- [browserContext.addInitScript(script[, arg])](#browsercontextaddinitscriptscript-arg) -- [browserContext.browser()](#browsercontextbrowser) -- [browserContext.clearCookies()](#browsercontextclearcookies) -- [browserContext.clearPermissions()](#browsercontextclearpermissions) -- [browserContext.close()](#browsercontextclose) -- [browserContext.cookies([urls])](#browsercontextcookiesurls) -- [browserContext.exposeBinding(name, playwrightBinding[, options])](#browsercontextexposebindingname-playwrightbinding-options) -- [browserContext.exposeFunction(name, playwrightFunction)](#browsercontextexposefunctionname-playwrightfunction) -- [browserContext.grantPermissions(permissions[][, options])](#browsercontextgrantpermissionspermissions-options) -- [browserContext.newPage()](#browsercontextnewpage) -- [browserContext.pages()](#browsercontextpages) -- [browserContext.route(url, handler)](#browsercontextrouteurl-handler) -- [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout) -- [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) -- [browserContext.setExtraHTTPHeaders(headers)](#browsercontextsetextrahttpheadersheaders) -- [browserContext.setGeolocation(geolocation)](#browsercontextsetgeolocationgeolocation) -- [browserContext.setHTTPCredentials(httpCredentials)](#browsercontextsethttpcredentialshttpcredentials) -- [browserContext.setOffline(offline)](#browsercontextsetofflineoffline) -- [browserContext.storageState()](#browsercontextstoragestate) -- [browserContext.unroute(url[, handler])](#browsercontextunrouteurl-handler) -- [browserContext.waitForEvent(event[, optionsOrPredicate])](#browsercontextwaitforeventevent-optionsorpredicate) #### event: 'close' Emitted when Browser context gets closed. This might happen because of one of the following: -- Browser context is closed. -- Browser application is closed or crashed. -- The [`browser.close`](#browserclose) method was called. +* Browser context is closed. +* Browser application is closed or crashed. +* The [`browser.close`](#browserclose) method was called. #### event: 'page' - <[Page]> @@ -182,7 +151,7 @@ console.log(await page.evaluate('location.href')); > **NOTE** Use [`page.waitForLoadState([state[, options]])`](#pagewaitforloadstatestate-options) to wait until the page gets to a particular state (you should not need it in most cases). -#### browserContext.addCookies(cookies) +#### browserContext.addCookies - `cookies` <[Array]<[Object]>> - `name` <[string]> **required** - `value` <[string]> **required** @@ -199,7 +168,7 @@ gets to a particular state (you should not need it in most cases). await browserContext.addCookies([cookieObject1, cookieObject2]); ``` -#### browserContext.addInitScript(script[, arg]) +#### browserContext.addInitScript - `script` <[function]|[string]|[Object]> Script to be evaluated in all pages in the browser context. - `path` <[string]> Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). - `content` <[string]> Raw script content. @@ -207,8 +176,8 @@ await browserContext.addCookies([cookieObject1, cookieObject2]); - returns: <[Promise]> Adds a script which would be evaluated in one of the following scenarios: -- Whenever a page is created in the browser context or is navigated. -- Whenever a child frame is attached or navigated in any page in the browser context. In this case, the script is evaluated in the context of the newly attached frame. +* Whenever a page is created in the browser context or is navigated. +* Whenever a child frame is attached or navigated in any page in the browser context. In this case, the script is evaluated in the context of the newly attached frame. The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend the JavaScript environment, e.g. to seed `Math.random`. @@ -231,15 +200,15 @@ await browserContext.addInitScript({ arg])](#browsercontextaddinitscriptscript-arg) and [page.addInitScript(script[, arg])](#pageaddinitscriptscript-arg) is not defined. -#### browserContext.browser() +#### browserContext.browser - returns: <[null]|[Browser]> Returns the browser instance of the context. If it was launched as a persistent context null gets returned. -#### browserContext.clearCookies() +#### browserContext.clearCookies - returns: <[Promise]> Clears context cookies. -#### browserContext.clearPermissions() +#### browserContext.clearPermissions - returns: <[Promise]> Clears all permission overrides for the browser context. @@ -251,15 +220,15 @@ await context.grantPermissions(['clipboard-read']); context.clearPermissions(); ``` -#### browserContext.close() +#### browserContext.close - returns: <[Promise]> Closes the browser context. All the pages that belong to the browser context will be closed. > **NOTE** the default browser context cannot be closed. -#### browserContext.cookies([urls]) -- `urls` <[string]|[Array]<[string]>> +#### browserContext.cookies +- `urls` <[string]|[Array]<[string]>> Optional list of URLs. - returns: <[Promise]<[Array]<[Object]>>> - `name` <[string]> - `value` <[string]> @@ -273,7 +242,7 @@ Closes the browser context. All the pages that belong to the browser context wil If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs are returned. -#### browserContext.exposeBinding(name, playwrightBinding[, options]) +#### browserContext.exposeBinding - `name` <[string]> Name of the function on the window object. - `playwrightBinding` <[function]> Callback function that will be called in the Playwright's context. - `options` <[Object]> @@ -328,7 +297,7 @@ await page.setContent(` `); ``` -#### browserContext.exposeFunction(name, playwrightFunction) +#### browserContext.exposeFunction - `name` <[string]> Name of the function on the window object. - `playwrightFunction` <[function]> Callback function that will be called in the Playwright's context. - returns: <[Promise]> @@ -365,7 +334,7 @@ const crypto = require('crypto'); })(); ``` -#### browserContext.grantPermissions(permissions[][, options]) +#### browserContext.grantPermissions - `permissions` <[Array]<[string]>> A permission or an array of permissions to grant. Permissions can be one of the following values: - `'geolocation'` - `'midi'` @@ -390,15 +359,15 @@ const crypto = require('crypto'); Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin if specified. -#### browserContext.newPage() +#### browserContext.newPage - returns: <[Promise]<[Page]>> Creates a new page in the browser context. -#### browserContext.pages() +#### browserContext.pages - returns: <[Array]<[Page]>> All open pages in the context. Non visible pages, such as `"background_page"`, will not be listed here. You can find them using [chromiumBrowserContext.backgroundPages()](#chromiumbrowsercontextbackgroundpages). -#### browserContext.route(url, handler) +#### browserContext.route - `url` <[string]|[RegExp]|[function]\([URL]\):[boolean]> A glob pattern, regex pattern or predicate receiving [URL] to match while routing. - `handler` <[function]\([Route], [Request]\)> handler function to route the request. - returns: <[Promise]> @@ -431,22 +400,22 @@ when request matches both handlers. > **NOTE** Enabling routing disables http cache. -#### browserContext.setDefaultNavigationTimeout(timeout) +#### browserContext.setDefaultNavigationTimeout - `timeout` <[number]> Maximum navigation time in milliseconds This setting will change the default maximum navigation time for the following methods and related shortcuts: -- [page.goBack([options])](#pagegobackoptions) -- [page.goForward([options])](#pagegoforwardoptions) -- [page.goto(url[, options])](#pagegotourl-options) -- [page.reload([options])](#pagereloadoptions) -- [page.setContent(html[, options])](#pagesetcontenthtml-options) -- [page.waitForNavigation([options])](#pagewaitfornavigationoptions) +* [page.goBack([options])](#pagegobackoptions) +* [page.goForward([options])](#pagegoforwardoptions) +* [page.goto(url[, options])](#pagegotourl-options) +* [page.reload([options])](#pagereloadoptions) +* [page.setContent(html[, options])](#pagesetcontenthtml-options) +* [page.waitForNavigation([options])](#pagewaitfornavigationoptions) > **NOTE** [`page.setDefaultNavigationTimeout`](#pagesetdefaultnavigationtimeouttimeout) and [`page.setDefaultTimeout`](#pagesetdefaulttimeouttimeout) take priority over [`browserContext.setDefaultNavigationTimeout`](#browsercontextsetdefaultnavigationtimeouttimeout). -#### browserContext.setDefaultTimeout(timeout) +#### browserContext.setDefaultTimeout - `timeout` <[number]> Maximum time in milliseconds This setting will change the default maximum time for all the methods accepting `timeout` option. @@ -456,7 +425,7 @@ This setting will change the default maximum time for all the methods accepting [`browserContext.setDefaultNavigationTimeout`](#browsercontextsetdefaultnavigationtimeouttimeout) take priority over [`browserContext.setDefaultTimeout`](#browsercontextsetdefaulttimeouttimeout). -#### browserContext.setExtraHTTPHeaders(headers) +#### browserContext.setExtraHTTPHeaders - `headers` <[Object]<[string], [string]>> An object containing additional HTTP headers to be sent with every request. All header values must be strings. - returns: <[Promise]> @@ -466,7 +435,7 @@ overrides a particular header, page-specific header value will be used instead o > **NOTE** `browserContext.setExtraHTTPHeaders` does not guarantee the order of headers in the outgoing requests. -#### browserContext.setGeolocation(geolocation) +#### browserContext.setGeolocation - `geolocation` <[null]|[Object]> - `latitude` <[number]> Latitude between -90 and 90. **required** - `longitude` <[number]> Longitude between -180 and 180. **required** @@ -482,7 +451,7 @@ await browserContext.setGeolocation({latitude: 59.95, longitude: 30.31667}); > **NOTE** Consider using [browserContext.grantPermissions](#browsercontextgrantpermissionspermissions-options) to grant permissions for the browser context pages to read its geolocation. -#### browserContext.setHTTPCredentials(httpCredentials) +#### browserContext.setHTTPCredentials - `httpCredentials` <[null]|[Object]> - `username` <[string]> **required** - `password` <[string]> **required** @@ -494,11 +463,11 @@ Provide credentials for [HTTP authentication](https://developer.mozilla.org/en-U `null` to disable authentication will be unreliable. To remove or replace credentials, create a new browser context instead. -#### browserContext.setOffline(offline) +#### browserContext.setOffline - `offline` <[boolean]> Whether to emulate network being offline for the browser context. - returns: <[Promise]> -#### browserContext.storageState() +#### browserContext.storageState - returns: <[Promise]<[Object]>> - `cookies` <[Array]<[Object]>> - `name` <[string]> @@ -517,17 +486,17 @@ instead. Returns storage state for this browser context, contains current cookies and local storage snapshot. -#### browserContext.unroute(url[, handler]) +#### browserContext.unroute - `url` <[string]|[RegExp]|[function]\([URL]\):[boolean]> A glob pattern, regex pattern or predicate receiving [URL] used to register a routing with [browserContext.route(url, handler)](#browsercontextrouteurl-handler). -- `handler` <[function]\([Route], [Request]\)> Handler function used to register a routing with [browserContext.route(url, handler)](#browsercontextrouteurl-handler). +- `handler` <[function]\([Route], [Request]\)> Optional handler function used to register a routing with [browserContext.route(url, handler)](#browsercontextrouteurl-handler). - returns: <[Promise]> Removes a route created with [browserContext.route(url, handler)](#browsercontextrouteurl-handler). When `handler` is not specified, removes all routes for the `url`. -#### browserContext.waitForEvent(event[, optionsOrPredicate]) +#### browserContext.waitForEvent - `event` <[string]> Event name, same one would pass into `browserContext.on(event)`. -- `optionsOrPredicate` <[Function]|[Object]> Either a predicate that receives an event or an options object. +- `optionsOrPredicate` <[Function]|[Object]> Either a predicate that receives an event or an options object. Optional. - `predicate` <[Function]> receives the event data and resolves to truthy value when the waiting should resolve. - %%-wait-for-timeout-%% - returns: <[Promise]<[Object]>> Promise which resolves to the event data value. @@ -584,94 +553,6 @@ page.removeListener('request', logRequest); ``` -- [event: 'close'](#event-close-1) -- [event: 'console'](#event-console) -- [event: 'crash'](#event-crash) -- [event: 'dialog'](#event-dialog) -- [event: 'domcontentloaded'](#event-domcontentloaded) -- [event: 'download'](#event-download) -- [event: 'filechooser'](#event-filechooser) -- [event: 'frameattached'](#event-frameattached) -- [event: 'framedetached'](#event-framedetached) -- [event: 'framenavigated'](#event-framenavigated) -- [event: 'load'](#event-load) -- [event: 'pageerror'](#event-pageerror) -- [event: 'popup'](#event-popup) -- [event: 'request'](#event-request) -- [event: 'requestfailed'](#event-requestfailed) -- [event: 'requestfinished'](#event-requestfinished) -- [event: 'response'](#event-response) -- [event: 'websocket'](#event-websocket) -- [event: 'worker'](#event-worker) -- [page.$(selector)](#pageselector) -- [page.$$(selector)](#pageselector-1) -- [page.$eval(selector, pageFunction[, arg])](#pageevalselector-pagefunction-arg) -- [page.$$eval(selector, pageFunction[, arg])](#pageevalselector-pagefunction-arg-1) -- [page.accessibility](#pageaccessibility) -- [page.addInitScript(script[, arg])](#pageaddinitscriptscript-arg) -- [page.addScriptTag(options)](#pageaddscripttagoptions) -- [page.addStyleTag(options)](#pageaddstyletagoptions) -- [page.bringToFront()](#pagebringtofront) -- [page.check(selector, [options])](#pagecheckselector-options) -- [page.click(selector[, options])](#pageclickselector-options) -- [page.close([options])](#pagecloseoptions) -- [page.content()](#pagecontent) -- [page.context()](#pagecontext) -- [page.coverage](#pagecoverage) -- [page.dblclick(selector[, options])](#pagedblclickselector-options) -- [page.dispatchEvent(selector, type[, eventInit, options])](#pagedispatcheventselector-type-eventinit-options) -- [page.emulateMedia(options)](#pageemulatemediaoptions) -- [page.evaluate(pageFunction[, arg])](#pageevaluatepagefunction-arg) -- [page.evaluateHandle(pageFunction[, arg])](#pageevaluatehandlepagefunction-arg) -- [page.exposeBinding(name, playwrightBinding[, options])](#pageexposebindingname-playwrightbinding-options) -- [page.exposeFunction(name, playwrightFunction)](#pageexposefunctionname-playwrightfunction) -- [page.fill(selector, value[, options])](#pagefillselector-value-options) -- [page.focus(selector[, options])](#pagefocusselector-options) -- [page.frame(options)](#pageframeoptions) -- [page.frames()](#pageframes) -- [page.getAttribute(selector, name[, options])](#pagegetattributeselector-name-options) -- [page.goBack([options])](#pagegobackoptions) -- [page.goForward([options])](#pagegoforwardoptions) -- [page.goto(url[, options])](#pagegotourl-options) -- [page.hover(selector[, options])](#pagehoverselector-options) -- [page.innerHTML(selector[, options])](#pageinnerhtmlselector-options) -- [page.innerText(selector[, options])](#pageinnertextselector-options) -- [page.isClosed()](#pageisclosed) -- [page.keyboard](#pagekeyboard) -- [page.mainFrame()](#pagemainframe) -- [page.mouse](#pagemouse) -- [page.opener()](#pageopener) -- [page.pdf([options])](#pagepdfoptions) -- [page.press(selector, key[, options])](#pagepressselector-key-options) -- [page.reload([options])](#pagereloadoptions) -- [page.route(url, handler)](#pagerouteurl-handler) -- [page.screenshot([options])](#pagescreenshotoptions) -- [page.selectOption(selector, values[, options])](#pageselectoptionselector-values-options) -- [page.setContent(html[, options])](#pagesetcontenthtml-options) -- [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) -- [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) -- [page.setExtraHTTPHeaders(headers)](#pagesetextrahttpheadersheaders) -- [page.setInputFiles(selector, files[, options])](#pagesetinputfilesselector-files-options) -- [page.setViewportSize(viewportSize)](#pagesetviewportsizeviewportsize) -- [page.tap(selector[, options])](#pagetapselector-options) -- [page.textContent(selector[, options])](#pagetextcontentselector-options) -- [page.title()](#pagetitle) -- [page.touchscreen](#pagetouchscreen) -- [page.type(selector, text[, options])](#pagetypeselector-text-options) -- [page.uncheck(selector, [options])](#pageuncheckselector-options) -- [page.unroute(url[, handler])](#pageunrouteurl-handler) -- [page.url()](#pageurl) -- [page.video()](#pagevideo) -- [page.viewportSize()](#pageviewportsize) -- [page.waitForEvent(event[, optionsOrPredicate])](#pagewaitforeventevent-optionsorpredicate) -- [page.waitForFunction(pageFunction[, arg, options])](#pagewaitforfunctionpagefunction-arg-options) -- [page.waitForLoadState([state[, options]])](#pagewaitforloadstatestate-options) -- [page.waitForNavigation([options])](#pagewaitfornavigationoptions) -- [page.waitForRequest(urlOrPredicate[, options])](#pagewaitforrequesturlorpredicate-options) -- [page.waitForResponse(urlOrPredicate[, options])](#pagewaitforresponseurlorpredicate-options) -- [page.waitForSelector(selector[, options])](#pagewaitforselectorselector-options) -- [page.waitForTimeout(timeout)](#pagewaitfortimeouttimeout) -- [page.workers()](#pageworkers) #### event: 'close' @@ -844,7 +725,7 @@ Emitted when <[WebSocket]> request is sent. Emitted when a dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is spawned by the page. -#### page.$(selector) +#### page.$ - %%-query-selector-%% - returns: <[Promise]<[null]|[ElementHandle]>> @@ -853,7 +734,7 @@ return value resolves to `null`. Shortcut for [page.mainFrame().$(selector)](#frameselector). -#### page.$$(selector) +#### page.$$ - %%-query-selector-%% - returns: <[Promise]<[Array]<[ElementHandle]>>> @@ -862,7 +743,7 @@ return value resolves to `[]`. Shortcut for [page.mainFrame().$$(selector)](#frameselector-1). -#### page.$eval(selector, pageFunction[, arg]) +#### page.$eval - %%-query-selector-%% - `pageFunction` <[function]\([Element]\)> Function to be evaluated in browser context - `arg` <[EvaluationArgument]> Optional argument to pass to `pageFunction` @@ -883,7 +764,7 @@ const html = await page.$eval('.main-container', (e, suffix) => e.outerHTML + su Shortcut for [page.mainFrame().$eval(selector, pageFunction)](#frameevalselector-pagefunction-arg). -#### page.$$eval(selector, pageFunction[, arg]) +#### page.$$eval - %%-query-selector-%% - `pageFunction` <[function]\([Array]<[Element]>\)> Function to be evaluated in browser context - `arg` <[EvaluationArgument]> Optional argument to pass to `pageFunction` @@ -903,7 +784,7 @@ const divsCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 1 #### page.accessibility - returns: <[Accessibility]> -#### page.addInitScript(script[, arg]) +#### page.addInitScript - `script` <[function]|[string]|[Object]> Script to be evaluated in the page. - `path` <[string]> Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). - `content` <[string]> Raw script content. @@ -911,8 +792,8 @@ const divsCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 1 - returns: <[Promise]> Adds a script which would be evaluated in one of the following scenarios: -- Whenever the page is navigated. -- Whenever the child frame is attached or navigated. In this case, the script is evaluated in the context of the newly attached frame. +* Whenever the page is navigated. +* Whenever the child frame is attached or navigated. In this case, the script is evaluated in the context of the newly attached frame. The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend the JavaScript environment, e.g. to seed `Math.random`. @@ -932,8 +813,8 @@ await page.addInitScript(preloadFile); arg])](#browsercontextaddinitscriptscript-arg) and [page.addInitScript(script[, arg])](#pageaddinitscriptscript-arg) is not defined. -#### page.addScriptTag(options) -- `options` <[Object]> +#### page.addScriptTag +- `script` <[Object]> - `url` <[string]> URL of a script to be added. - `path` <[string]> Path to the JavaScript file to be injected into frame. If `path` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). - `content` <[string]> Raw JavaScript content to be injected into frame. @@ -942,10 +823,10 @@ not defined. Adds a `