From 95c502d2742eb71139af15d6cb6d7e6c9921d24e Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Thu, 3 Dec 2020 09:11:48 -0800 Subject: [PATCH] docs: use templates to reuse documentation properties (#4578) --- docs-src/api-body.md | 699 ++++++++++++++--------------------------- docs-src/api-params.md | 120 +++++++ docs/api.md | 296 ++++++++--------- utils/doclint/cli.js | 7 +- utils/parse_md.js | 156 +++++++++ 5 files changed, 667 insertions(+), 611 deletions(-) create mode 100644 docs-src/api-params.md create mode 100644 utils/parse_md.js diff --git a/docs-src/api-body.md b/docs-src/api-body.md index 2418728d73..e3c4e09528 100644 --- a/docs-src/api-body.md +++ b/docs-src/api-body.md @@ -64,64 +64,9 @@ Indicates that the browser is connected. #### browser.newContext([options]) - `options` <[Object]> - - `acceptDownloads` <[boolean]> Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled. - - `ignoreHTTPSErrors` <[boolean]> Whether to ignore HTTPS errors during navigation. Defaults to `false`. - - `bypassCSP` <[boolean]> Toggles bypassing page's Content-Security-Policy. - - `viewport` <[null]|[Object]> Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `null` disables the default viewport. - - `width` <[number]> page width in pixels. - - `height` <[number]> page height in pixels. - - `userAgent` <[string]> Specific user agent to use in this context. - - `deviceScaleFactor` <[number]> Specify device scale factor (can be thought of as dpr). Defaults to `1`. - - `isMobile` <[boolean]> Whether the `meta viewport` tag is taken into account and touch events are enabled. Defaults to `false`. Not supported in Firefox. - - `hasTouch` <[boolean]> Specifies if viewport supports touch events. Defaults to false. - - `javaScriptEnabled` <[boolean]> Whether or not to enable JavaScript in the context. Defaults to true. - - `timezoneId` <[string]> Changes the timezone of the context. See [ICU’s `metaZones.txt`](https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1) for a list of supported timezone IDs. - - `geolocation` <[Object]> - - `latitude` <[number]> Latitude between -90 and 90. - - `longitude` <[number]> Longitude between -180 and 180. - - `accuracy` <[number]> Non-negative accuracy value. Defaults to `0`. - - `locale` <[string]> Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, `Accept-Language` request header value as well as number and date formatting rules. - - `permissions` <[Array]<[string]>> A list of permissions to grant to all pages in this context. See [browserContext.grantPermissions](#browsercontextgrantpermissionspermissions-options) for more details. - - `extraHTTPHeaders` <[Object]<[string], [string]>> An object containing additional HTTP headers to be sent with every request. All header values must be strings. - - `offline` <[boolean]> Whether to emulate network being offline. Defaults to `false`. - - `httpCredentials` <[Object]> Credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication). - - `username` <[string]> - - `password` <[string]> - - `colorScheme` <"light"|"dark"|"no-preference"> Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See [page.emulateMedia(options)](#pageemulatemediaoptions) for more details. Defaults to '`light`'. - - `logger` <[Logger]> Logger sink for Playwright logging. - - `proxy` <[Object]> Network proxy settings to use with this context. Note that browser needs to be launched with the global proxy for this option to work. If all contexts override the proxy, global proxy will be never used and can be any string, for example `launch({ proxy: { server: 'per-context' } })`. - - `server` <[string]> Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example `http://myproxy.com:3128` or `socks5://myproxy.com:3128`. Short form `myproxy.com:3128` is considered an HTTP proxy. - - `bypass` <[string]> Optional coma-separated domains to bypass proxy, for example `".com, chromium.org, .domain.com"`. - - `username` <[string]> Optional username to use if HTTP proxy requires authentication. - - `password` <[string]> Optional password to use if HTTP proxy requires authentication. - - `videosPath` <[string]> **NOTE** Use `recordVideo` instead, it takes precedence over `videosPath`. Enables video recording for all pages to `videosPath` directory. If not specified, videos are not recorded. Make sure to await [`browserContext.close`](#browsercontextclose) for videos to be saved. - - `videoSize` <[Object]> **NOTE** Use `recordVideo` instead, it takes precedence over `videoSize`. Specifies dimensions of the automatically recorded video. Can only be used if `videosPath` is set. If not specified the size will be equal to `viewport`. If `viewport` is not configured explicitly the video size defaults to 1280x720. Actual picture of the page will be scaled down if necessary to fit specified size. - - `width` <[number]> Video frame width. - - `height` <[number]> Video frame height. - - `recordHar` <[Object]> Enables [HAR](http://www.softwareishard.com/blog/har-12-spec) recording for all pages into `recordHar.path` file. If not specified, the HAR is not recorded. Make sure to await [`browserContext.close`](#browsercontextclose) for the HAR to be saved. - - `omitContent` <[boolean]> Optional setting to control whether to omit request content from the HAR. Defaults to `false`. - - `path` <[string]> Path on the filesystem to write the HAR file to. - - `recordVideo` <[Object]> Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. Make sure to await [`browserContext.close`](#browsercontextclose) for videos to be saved. - - `dir` <[string]> Path to the directory to put videos into. - - `size` <[Object]> Optional dimensions of the recorded videos. If not specified the size will be equal to `viewport`. If `viewport` is not configured explicitly the video size defaults to 1280x720. Actual picture of each page will be scaled down if necessary to fit the specified size. - - `width` <[number]> Video frame width. - - `height` <[number]> Video frame height. - - `storageState` <[Object]> Populates context with given storage state. This method can be used to initialize context with logged-in information obtained via [browserContext.storageState()](#browsercontextstoragestate). - - `cookies` <[Array]<[Object]>> Optional cookies to set for context - - `name` <[string]> **required** - - `value` <[string]> **required** - - `url` <[string]> Optional either url or domain / path are required - - `domain` <[string]> Optional either url or domain / path are required - - `path` <[string]> Optional either url or domain / path are required - - `expires` <[number]> Optional Unix time in seconds. - - `httpOnly` <[boolean]> Optional httpOnly flag - - `secure` <[boolean]> Optional secure flag - - `sameSite` <"Strict"|"Lax"|"None"> Optional sameSite flag - - `origins` <[Array]<[Object]>> Optional localStorage to set for context - - `origin` <[string]> - - `localStorage` <[Array]<[Object]>> - - `name` <[string]> - - `value` <[string]> + - %%-shared-context-params-%% + - %%-context-proxy-params-%% + - %%-context-storage-state-%% - returns: <[Promise]<[BrowserContext]>> Creates a new browser context. It won't share cookies/cache with other browser contexts. @@ -139,64 +84,9 @@ Creates a new browser context. It won't share cookies/cache with other browser c #### browser.newPage([options]) - `options` <[Object]> - - `acceptDownloads` <[boolean]> Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled. - - `ignoreHTTPSErrors` <[boolean]> Whether to ignore HTTPS errors during navigation. Defaults to `false`. - - `bypassCSP` <[boolean]> Toggles bypassing page's Content-Security-Policy. - - `viewport` <[null]|[Object]> Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `null` disables the default viewport. - - `width` <[number]> page width in pixels. - - `height` <[number]> page height in pixels. - - `userAgent` <[string]> Specific user agent to use in this context. - - `deviceScaleFactor` <[number]> Specify device scale factor (can be thought of as dpr). Defaults to `1`. - - `isMobile` <[boolean]> Whether the `meta viewport` tag is taken into account and touch events are enabled. Defaults to `false`. Not supported in Firefox. - - `hasTouch` <[boolean]> Specifies if viewport supports touch events. Defaults to false. - - `javaScriptEnabled` <[boolean]> Whether or not to enable JavaScript in the context. Defaults to `true`. - - `timezoneId` <[string]> Changes the timezone of the context. See [ICU’s `metaZones.txt`](https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1) for a list of supported timezone IDs. - - `geolocation` <[Object]> - - `latitude` <[number]> Latitude between -90 and 90. - - `longitude` <[number]> Longitude between -180 and 180. - - `accuracy` <[number]> Non-negative accuracy value. Defaults to `0`. - - `locale` <[string]> Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, `Accept-Language` request header value as well as number and date formatting rules. - - `permissions` <[Array]<[string]>> A list of permissions to grant to all pages in this context. See [browserContext.grantPermissions](#browsercontextgrantpermissionspermissions-options) for more details. - - `extraHTTPHeaders` <[Object]<[string], [string]>> An object containing additional HTTP headers to be sent with every request. All header values must be strings. - - `offline` <[boolean]> Whether to emulate network being offline. Defaults to `false`. - - `httpCredentials` <[Object]> Credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication). - - `username` <[string]> - - `password` <[string]> - - `colorScheme` <"light"|"dark"|"no-preference"> Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See [page.emulateMedia(options)](#pageemulatemediaoptions) for more details. Defaults to '`light`'. - - `logger` <[Logger]> Logger sink for Playwright logging. - - `proxy` <[Object]> Network proxy settings to use with this context. Note that browser needs to be launched with the global proxy for this option to work. If all contexts override the proxy, global proxy will be never used and can be any string, for example `launch({ proxy: { server: 'per-context' } })`. - - `server` <[string]> Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example `http://myproxy.com:3128` or `socks5://myproxy.com:3128`. Short form `myproxy.com:3128` is considered an HTTP proxy. - - `bypass` <[string]> Optional coma-separated domains to bypass proxy, for example `".com, chromium.org, .domain.com"`. - - `username` <[string]> Optional username to use if HTTP proxy requires authentication. - - `password` <[string]> Optional password to use if HTTP proxy requires authentication. - - `videosPath` <[string]> **NOTE** Use `recordVideo` instead, it takes precedence over `videosPath`. Enables video recording for all pages to `videosPath` directory. If not specified, videos are not recorded. Make sure to await [`page.close`](#pagecloseoptions) for videos to be saved. - - `videoSize` <[Object]> **NOTE** Use `recordVideo` instead, it takes precedence over `videoSize`. Specifies dimensions of the automatically recorded video. Can only be used if `videosPath` is set. If not specified the size will be equal to `viewport`. If `viewport` is not configured explicitly the video size defaults to 1280x720. Actual picture of the page will be scaled down if necessary to fit specified size. - - `width` <[number]> Video frame width. - - `height` <[number]> Video frame height. - - `recordHar` <[Object]> Enables [HAR](http://www.softwareishard.com/blog/har-12-spec) recording for all pages into `recordHar.path` file. If not specified, the HAR is not recorded. Make sure to await [`page.close`](#pagecloseoptions) for the HAR to be saved. - - `omitContent` <[boolean]> Optional setting to control whether to omit request content from the HAR. Defaults to `false`. - - `path` <[string]> Path on the filesystem to write the HAR file to. - - `recordVideo` <[Object]> Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. Make sure to await [`page.close`](#pagecloseoptions) for videos to be saved. - - `dir` <[string]> Path to the directory to put videos into. - - `size` <[Object]> Optional dimensions of the recorded videos. If not specified the size will be equal to `viewport`. If `viewport` is not configured explicitly the video size defaults to 1280x720. Actual picture of each page will be scaled down if necessary to fit the specified size. - - `width` <[number]> Video frame width. - - `height` <[number]> Video frame height. - - `storageState` <[Object]> Populates context with given storage state. This method can be used to initialize context with logged-in information obtained via [browserContext.storageState()](#browsercontextstoragestate). - - `cookies` <[Array]<[Object]>> Optional cookies to set for context - - `name` <[string]> **required** - - `value` <[string]> **required** - - `url` <[string]> Optional either url or domain / path are required - - `domain` <[string]> Optional either url or domain / path are required - - `path` <[string]> Optional either url or domain / path are required - - `expires` <[number]> Optional Unix time in seconds. - - `httpOnly` <[boolean]> Optional httpOnly flag - - `secure` <[boolean]> Optional secure flag - - `sameSite` <"Strict"|"Lax"|"None"> Optional sameSite flag - - `origins` <[Array]<[Object]>> Optional localStorage to set for context - - `origin` <[string]> - - `localStorage` <[Array]<[Object]>> - - `name` <[string]> - - `value` <[string]> + - %%-shared-context-params-%% + - %%-context-proxy-params-%% + - %%-context-storage-state-%% - returns: <[Promise]<[Page]>> Creates a new page in a new browser context. Closing this page will close the context as well. @@ -609,7 +499,7 @@ Removes a route created with [browserContext.route(url, handler)](#browsercontex - `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. - `predicate` <[Function]> receives the event data and resolves to truthy value when the waiting should resolve. - - `timeout` <[number]> maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout). + - %%-wait-for-timeout-%% - returns: <[Promise]<[Object]>> Promise which resolves to the event data value. Waits for event to fire and passes its value into the predicate function. Resolves when the predicate returns truthy value. Will throw an error if the context closes before the event @@ -899,7 +789,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) -- `selector` <[string]> A selector to query page for. See [working with selectors](#working-with-selectors) for more details. +- %%-query-selector-%% - returns: <[Promise]<[null]|[ElementHandle]>> The method finds an element matching the specified selector within the page. If no elements match the selector, the return value resolves to `null`. @@ -907,7 +797,7 @@ The method finds an element matching the specified selector within the page. If Shortcut for [page.mainFrame().$(selector)](#frameselector). #### page.$$(selector) -- `selector` <[string]> A selector to query page for. See [working with selectors](#working-with-selectors) for more details. +- %%-query-selector-%% - returns: <[Promise]<[Array]<[ElementHandle]>>> The method finds all elements matching the specified selector within the page. If no elements match the selector, the return value resolves to `[]`. @@ -915,7 +805,7 @@ The method finds all elements matching the specified selector within the page. I Shortcut for [page.mainFrame().$$(selector)](#frameselector-1). #### page.$eval(selector, pageFunction[, arg]) -- `selector` <[string]> A selector to query page for. See [working with selectors](#working-with-selectors) for more details. +- %%-query-selector-%% - `pageFunction` <[function]\([Element]\)> Function to be evaluated in browser context - `arg` <[EvaluationArgument]> Optional argument to pass to `pageFunction` - returns: <[Promise]<[Serializable]>> Promise which resolves to the return value of `pageFunction` @@ -934,7 +824,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]) -- `selector` <[string]> A selector to query page for. See [working with selectors](#working-with-selectors) for more details. +- %%-query-selector-%% - `pageFunction` <[function]\([Array]<[Element]>\)> Function to be evaluated in browser context - `arg` <[EvaluationArgument]> Optional argument to pass to `pageFunction` - returns: <[Promise]<[Serializable]>> Promise which resolves to the return value of `pageFunction` @@ -1009,11 +899,11 @@ Brings page to front (activates tab). #### page.check(selector, [options]) -- `selector` <[string]> A selector to search for checkbox or radio button to check. If there are multiple elements satisfying the selector, the first will be checked. See [working with selectors](#working-with-selectors) for more details. +- %%-input-selector-%% - `options` <[Object]> - - `force` <[boolean]> Whether to bypass the [actionability](./actionability.md) checks. Defaults to `false`. - - `noWaitAfter` <[boolean]> 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`. - - `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. + - %%-input-force-%% + - %%-input-no-wait-after-%% + - %%-input-timeout-%% - returns: <[Promise]> Promise that resolves when the element matching `selector` is successfully checked. This method checks an element matching `selector` by performing the following steps: @@ -1030,18 +920,16 @@ When all steps combined have not finished during the specified `timeout`, this m Shortcut for [page.mainFrame().check(selector[, options])](#framecheckselector-options). #### page.click(selector[, options]) -- `selector` <[string]> A selector to search for element to click. If there are multiple elements satisfying the selector, the first will be clicked. See [working with selectors](#working-with-selectors) for more details. +- %%-input-selector-%% - `options` <[Object]> - - `button` <"left"|"right"|"middle"> Defaults to `left`. - - `clickCount` <[number]> defaults to 1. See [UIEvent.detail]. - - `delay` <[number]> Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. - - `position` <[Object]> A point to click relative to the top-left corner of element padding box. If not specified, clicks to some visible point of the element. - - `x` <[number]> - - `y` <[number]> - - `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> Modifier keys to press. Ensures that only these modifiers are pressed during the click, and then restores current modifiers back. If not specified, currently pressed modifiers are used. - - `force` <[boolean]> Whether to bypass the [actionability](./actionability.md) checks. Defaults to `false`. - - `noWaitAfter` <[boolean]> 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`. - - `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. + - %%-input-button-%% + - %%-input-click-count-%% + - %%-input-down-up-delay-%% + - %%-input-position-%% + - %%-input-modifiers-%% + - %%-input-force-%% + - %%-input-no-wait-after-%% + - %%-input-timeout-%% - returns: <[Promise]> Promise that resolves when the element matching `selector` is successfully clicked. This method clicks an element matching `selector` by performing the following steps: @@ -1087,17 +975,15 @@ Get the browser context that the page belongs to. Browser-specific Coverage implementation, only available for Chromium atm. See [ChromiumCoverage](#class-chromiumcoverage) for more details. #### page.dblclick(selector[, options]) -- `selector` <[string]> A selector to search for element to double click. If there are multiple elements satisfying the selector, the first will be double clicked. See [working with selectors](#working-with-selectors) for more details. +- %%-input-selector-%% - `options` <[Object]> - - `button` <"left"|"right"|"middle"> Defaults to `left`. - - `delay` <[number]> Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. - - `position` <[Object]> A point to double click relative to the top-left corner of element padding box. If not specified, double clicks to some visible point of the element. - - `x` <[number]> - - `y` <[number]> - - `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> Modifier keys to press. Ensures that only these modifiers are pressed during the double click, and then restores current modifiers back. If not specified, currently pressed modifiers are used. - - `force` <[boolean]> Whether to bypass the [actionability](./actionability.md) checks. Defaults to `false`. - - `noWaitAfter` <[boolean]> 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`. - - `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. + - %%-input-button-%% + - %%-input-down-up-delay-%% + - %%-input-position-%% + - %%-input-modifiers-%% + - %%-input-force-%% + - %%-input-no-wait-after-%% + - %%-input-timeout-%% - returns: <[Promise]> Promise that resolves when the element matching `selector` is successfully double clicked. This method double clicks an element matching `selector` by performing the following steps: @@ -1115,11 +1001,11 @@ Shortcut for [page.mainFrame().dblclick(selector[, options])](#framedblclicksele #### page.dispatchEvent(selector, type[, eventInit, options]) -- `selector` <[string]> A selector to search for element to use. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](#working-with-selectors) for more details. +- %%-input-selector-%% - `type` <[string]> DOM event type: `"click"`, `"dragstart"`, etc. - `eventInit` <[EvaluationArgument]> event-specific initialization properties. - `options` <[Object]> - - `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. + - %%-input-timeout-%% - returns: <[Promise]> The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the elment, `click` is dispatched. This is equivalend to calling [`element.click()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click). @@ -1357,11 +1243,11 @@ const fs = require('fs'); ``` #### page.fill(selector, value[, options]) -- `selector` <[string]> A selector to query page for. See [working with selectors](#working-with-selectors) for more details. +- %%-input-selector-%% - `value` <[string]> Value to fill for the ``, `