diff --git a/docs-src/api-body.md b/docs-src/api-body.md index f828a986f9..6acf3d4be1 100644 --- a/docs-src/api-body.md +++ b/docs-src/api-body.md @@ -2,7 +2,7 @@ * extends: [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter) A Browser is created when Playwright connects to a browser instance, either through -[`browserType.launch`](#browsertypelaunchoptions) or [`browserType.connect`](#browsertypeconnectoptions). +[browserType.launch()]() or [browserType.connect()](). An example of using a [Browser] to create a [Page]: @@ -18,8 +18,8 @@ const { firefox } = require('playwright'); // Or 'chromium' or 'webkit'. ``` See [ChromiumBrowser], [FirefoxBrowser] and [WebKitBrowser] for browser-specific features. Note that -[browserType.connect(options)](#browsertypeconnect) and -[browserType.launch([options])](#browsertypelaunchoptions) always return a specific browser instance, based on the +[browserType.connect()]() and +[browserType.launch()]() always return a specific browser instance, based on the browser being connected to or launched. @@ -29,15 +29,15 @@ browser being connected to or launched. 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. +* The [browser.close()]() method was called. #### browser.close - returns: <[Promise]> -In case this browser is obtained using [browserType.launch](#browsertypelaunchoptions), closes the browser and all of +In case this browser is obtained using [browserType.launch()](), closes the browser and all of its pages (if any were opened). -In case this browser is obtained using [browserType.connect](#browsertypeconnect), clears all created contexts +In case this browser is obtained using [browserType.connect()](), 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. @@ -90,8 +90,8 @@ Creates a new browser context. It won't share cookies/cache with other browser c Creates a new page in a new browser context. Closing this page will close the context as well. This is a convenience API that should only be used for the single-page scenarios and short snippets. Production code and -testing frameworks should explicitly create [browser.newContext](#browsernewcontextoptions) followed by the -[browserContext.newPage](#browsercontextnewpage) to control their exact life times. +testing frameworks should explicitly create [browser.newContext()]() followed by the +[browserContext.newPage()]() to control their exact life times. #### browser.version - returns: <[string]> @@ -127,13 +127,13 @@ await context.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. +* The [browser.close()]() method was called. #### event: 'page' - <[Page]> The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event will -also fire for popup pages. See also [`Page.on('popup')`](#event-popup) to receive events about popups relevant to a +also fire for popup pages. See also [page.on('popup')]() to receive events about popups relevant to a specific page. The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a @@ -148,7 +148,7 @@ const [page] = await Promise.all([ console.log(await page.evaluate('location.href')); ``` -> **NOTE** Use [`page.waitForLoadState([state[, options]])`](#pagewaitforloadstatestate-options) to wait until the page +> **NOTE** Use [page.waitForLoadState()]() to wait until the page gets to a particular state (you should not need it in most cases). #### browserContext.addCookies @@ -196,8 +196,7 @@ await browserContext.addInitScript({ }); ``` -> **NOTE** The order of evaluation of multiple scripts installed via [browserContext.addInitScript(script[, -arg])](#browsercontextaddinitscriptscript-arg) and [page.addInitScript(script[, arg])](#pageaddinitscriptscript-arg) is +> **NOTE** The order of evaluation of multiple scripts installed via [browserContext.addInitScript()]() and [page.addInitScript()]() is not defined. #### browserContext.browser @@ -256,7 +255,7 @@ of `playwrightBinding`. If the `playwrightBinding` returns a [Promise], it will The first argument of the `playwrightBinding` function contains information about the caller: `{ browserContext: BrowserContext, page: Page, frame: Frame }`. -See [page.exposeBinding(name, playwrightBinding)](#pageexposebindingname-playwrightbinding-options) for page-only +See [page.exposeBinding()]() for page-only version. An example of exposing page URL to all frames in all pages in the context: @@ -308,7 +307,7 @@ of `playwrightFunction`. If the `playwrightFunction` returns a [Promise], it will be awaited. -See [page.exposeFunction(name, playwrightFunction)](#pageexposefunctionname-playwrightfunction) for page-only version. +See [page.exposeFunction()]() for page-only version. An example of adding an `md5` function to all pages in the context: @@ -365,7 +364,7 @@ specified. Creates a new page in the browser context. #### 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). +- 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()](). #### browserContext.route - `url` <[string]|[RegExp]|[function]\([URL]\):[boolean]> A glob pattern, regex pattern or predicate receiving [URL] to match while routing. @@ -395,7 +394,7 @@ await page.goto('https://example.com'); await browser.close(); ``` -Page routes (set up with [page.route(url, handler)](#pagerouteurl-handler)) take precedence over browser context routes +Page routes (set up with [page.route()]()) take precedence over browser context routes when request matches both handlers. > **NOTE** Enabling routing disables http cache. @@ -404,33 +403,33 @@ when request matches both handlers. - `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()]() +* [page.goForward()]() +* [page.goto()]() +* [page.reload()]() +* [page.setContent()]() +* [page.waitForNavigation()]() -> **NOTE** [`page.setDefaultNavigationTimeout`](#pagesetdefaultnavigationtimeouttimeout) and -[`page.setDefaultTimeout`](#pagesetdefaulttimeouttimeout) take priority over -[`browserContext.setDefaultNavigationTimeout`](#browsercontextsetdefaultnavigationtimeouttimeout). +> **NOTE** [page.setDefaultNavigationTimeout()]() and +[page.setDefaultTimeout()]() take priority over +[browserContext.setDefaultNavigationTimeout()](). #### browserContext.setDefaultTimeout - `timeout` <[number]> Maximum time in milliseconds This setting will change the default maximum time for all the methods accepting `timeout` option. -> **NOTE** [`page.setDefaultNavigationTimeout`](#pagesetdefaultnavigationtimeouttimeout), -[`page.setDefaultTimeout`](#pagesetdefaulttimeouttimeout) and -[`browserContext.setDefaultNavigationTimeout`](#browsercontextsetdefaultnavigationtimeouttimeout) take priority over -[`browserContext.setDefaultTimeout`](#browsercontextsetdefaulttimeouttimeout). +> **NOTE** [page.setDefaultNavigationTimeout()](), +[page.setDefaultTimeout()]() and +[browserContext.setDefaultNavigationTimeout()]() take priority over +[browserContext.setDefaultTimeout()](). #### 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]> The extra HTTP headers will be sent with every request initiated by any page in the context. These headers are merged -with page-specific extra HTTP headers set with [page.setExtraHTTPHeaders()](#pagesetextrahttpheadersheaders). If page +with page-specific extra HTTP headers set with [page.setExtraHTTPHeaders()](). If page overrides a particular header, page-specific header value will be used instead of the browser context header value. > **NOTE** `browserContext.setExtraHTTPHeaders` does not guarantee the order of headers in the outgoing requests. @@ -448,7 +447,7 @@ Sets the context's geolocation. Passing `null` or `undefined` emulates position await browserContext.setGeolocation({latitude: 59.95, longitude: 30.31667}); ``` -> **NOTE** Consider using [browserContext.grantPermissions](#browsercontextgrantpermissionspermissions-options) to grant +> **NOTE** Consider using [browserContext.grantPermissions()]() to grant permissions for the browser context pages to read its geolocation. #### browserContext.setHTTPCredentials @@ -487,11 +486,11 @@ instead. Returns storage state for this browser context, contains current cookies and local storage snapshot. #### 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]\)> Optional handler function used to register a routing with [browserContext.route(url, handler)](#browsercontextrouteurl-handler). +- `url` <[string]|[RegExp]|[function]\([URL]\):[boolean]> A glob pattern, regex pattern or predicate receiving [URL] used to register a routing with [browserContext.route()](). +- `handler` <[function]\([Route], [Request]\)> Optional handler function used to register a routing with [browserContext.route()](). - returns: <[Promise]> -Removes a route created with [browserContext.route(url, handler)](#browsercontextrouteurl-handler). When `handler` is +Removes a route created with [browserContext.route()](). When `handler` is not specified, removes all routes for the `url`. #### browserContext.waitForEvent @@ -612,7 +611,7 @@ await new Promise((resolve, reject) => { - <[Dialog]> Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Playwright can respond -to the dialog via [Dialog]'s [accept](#dialogacceptprompttext) or [dismiss](#dialogdismiss) methods. +to the dialog via [dialog.accept()]() or [dialog.dismiss()]() methods. #### event: 'domcontentloaded' @@ -633,7 +632,7 @@ download is not performed and user has no access to the downloaded files. - <[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`](#filechoosersetfilesfiles-options) that can be +respond to it via setting the input files using [fileChooser.setFiles()]() that can be uploaded after that. ```js @@ -670,7 +669,7 @@ Emitted when an uncaught exception happens within the page. - <[Page]> Page corresponding to "popup" window Emitted when the page opens a new tab or window. This event is emitted in addition to the -[`browserContext.on('page')`](#event-page), but only for popups relevant to this page. +[browserContext.on('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" is @@ -684,14 +683,14 @@ const [popup] = await Promise.all([ console.log(await popup.evaluate('location.href')); ``` -> **NOTE** Use [`page.waitForLoadState([state[, options]])`](#pagewaitforloadstatestate-options) to wait until the page +> **NOTE** Use [page.waitForLoadState()]() to wait until the page gets to a particular state (you should not need it in most cases). #### event: 'request' - <[Request]> Emitted when a page issues a request. The [request] object is read-only. In order to intercept and mutate requests, see -[`page.route()`](#pagerouteurl-handler) or [`browserContext.route()`](#browsercontextrouteurl-handler). +[page.route()]() or [browserContext.route()](). #### event: 'requestfailed' - <[Request]> @@ -699,8 +698,8 @@ Emitted when a page issues a request. The [request] object is read-only. In orde Emitted when a request fails, for example by timing out. > **NOTE** HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request -will complete with [`'requestfinished'`](#event-requestfinished) event and not with -[`'requestfailed'`](#event-requestfailed). +will complete with [page.on('requestfinished')]() event and not with +[page.on('requestfailed')](). #### event: 'requestfinished' - <[Request]> @@ -732,7 +731,7 @@ page. The method finds an element matching the specified selector within the page. If no elements match the selector, the return value resolves to `null`. -Shortcut for [page.mainFrame().$(selector)](#frameselector). +Shortcut for main frame's [frame.$()](). #### page.$$ - %%-query-selector-%% @@ -741,7 +740,7 @@ Shortcut for [page.mainFrame().$(selector)](#frameselector). The method finds all elements matching the specified selector within the page. If no elements match the selector, the return value resolves to `[]`. -Shortcut for [page.mainFrame().$$(selector)](#frameselector-1). +Shortcut for main frame's [frame.$$()](). #### page.$eval - %%-query-selector-%% @@ -762,7 +761,7 @@ const preloadHref = await page.$eval('link[rel=preload]', el => el.href); const html = await page.$eval('.main-container', (e, suffix) => e.outerHTML + suffix, 'hello'); ``` -Shortcut for [page.mainFrame().$eval(selector, pageFunction)](#frameevalselector-pagefunction-arg). +Shortcut for main frame's [frame.$eval()](). #### page.$$eval - %%-query-selector-%% @@ -809,8 +808,7 @@ const preloadFile = fs.readFileSync('./preload.js', 'utf8'); await page.addInitScript(preloadFile); ``` -> **NOTE** The order of evaluation of multiple scripts installed via [browserContext.addInitScript(script[, -arg])](#browsercontextaddinitscriptscript-arg) and [page.addInitScript(script[, arg])](#pageaddinitscriptscript-arg) is +> **NOTE** The order of evaluation of multiple scripts installed via [browserContext.addInitScript()]() and [page.addInitScript()]() is not defined. #### page.addScriptTag @@ -823,7 +821,7 @@ not defined. Adds a `