From 1717cbd3d5e45a4a7387b2ca83f015f8d15f1d50 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Sat, 5 Dec 2020 15:29:16 -0800 Subject: [PATCH] doc: describe return value as a part of method (#4608) --- docs-src/api-body.md | 1314 +++++++++++++++++++++++------------------- docs/api.md | 473 ++++++++++----- utils/doclint/cli.js | 22 +- utils/parse_md.js | 4 +- 4 files changed, 1087 insertions(+), 726 deletions(-) diff --git a/docs-src/api-body.md b/docs-src/api-body.md index f996d2c5cf..da1f2209ba 100644 --- a/docs-src/api-body.md +++ b/docs-src/api-body.md @@ -30,8 +30,7 @@ Emitted when Browser gets disconnected from the browser application. This might * Browser application is closed or crashed. * The [browser.close()]() method was called. -## method: Browser.close -- returns: <[Promise]> +## async method: Browser.close In case this browser is obtained using [browserType.launch()](), closes the browser and all of its pages (if any were opened). @@ -59,8 +58,8 @@ console.log(browser.contexts().length); // prints `1` Indicates that the browser is connected. -## method: Browser.newContext -- returns: <[Promise]<[BrowserContext]>> +## async method: Browser.newContext +- returns: <[BrowserContext]> Creates a new browser context. It won't share cookies/cache with other browser contexts. @@ -76,11 +75,13 @@ Creates a new browser context. It won't share cookies/cache with other browser c ``` ### option: Browser.newContext.-inline- = %%-shared-context-params-list-%% + ### option: Browser.newContext.proxy = %%-context-option-proxy-%% + ### option: Browser.newContext.storageState = %%-context-option-storage-state-%% -## method: Browser.newPage -- returns: <[Promise]<[Page]>> +## async method: Browser.newPage +- returns: <[Page]> Creates a new page in a new browser context. Closing this page will close the context as well. @@ -89,7 +90,9 @@ testing frameworks should explicitly create [browser.newContext()]() followed by control their exact life times. ### option: Browser.newPage.-inline- = %%-shared-context-params-list-%% + ### option: Browser.newPage.proxy = %%-context-option-proxy-%% + ### option: Browser.newPage.storageState = %%-context-option-storage-state-%% ## method: Browser.version @@ -149,8 +152,10 @@ console.log(await page.evaluate('location.href')); > **NOTE** Use [page.waitForLoadState()]() to wait until the page gets to a particular state (you should not need it in most cases). -## method: BrowserContext.addCookies -- returns: <[Promise]> +## async method: BrowserContext.addCookies + +Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can be +obtained via [browserContext.cookies()](). ```js await browserContext.addCookies([cookieObject1, cookieObject2]); @@ -168,13 +173,11 @@ await browserContext.addCookies([cookieObject1, cookieObject2]); - `secure` <[boolean]> - `sameSite` <"Strict"|"Lax"|"None"> -## method: BrowserContext.addInitScript -- returns: <[Promise]> +## async method: BrowserContext.addInitScript 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 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`. @@ -198,8 +201,7 @@ await browserContext.addInitScript({ ### param: BrowserContext.addInitScript.script - `script` <[function]|[string]|[Object]> - - `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). + - `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. Script to be evaluated in all pages in the browser context. @@ -210,16 +212,15 @@ Script to be evaluated in all pages in the browser context. Optional argument to pass to `script` (only supported when passing a function). ## method: BrowserContext.browser -- returns: <[null]|[Browser]> Returns the browser instance of the context. If it was launched as a persistent context - null gets returned. +- returns: <[null]|[Browser]> -## method: BrowserContext.clearCookies -- returns: <[Promise]> +Returns the browser instance of the context. If it was launched as a persistent context null gets returned. + +## async method: BrowserContext.clearCookies Clears context cookies. -## method: BrowserContext.clearPermissions -- returns: <[Promise]> +## async method: BrowserContext.clearPermissions Clears all permission overrides for the browser context. @@ -230,15 +231,14 @@ await context.grantPermissions(['clipboard-read']); context.clearPermissions(); ``` -## method: BrowserContext.close -- returns: <[Promise]> +## async method: BrowserContext.close Closes the browser context. All the pages that belong to the browser context will be closed. > **NOTE** the default browser context cannot be closed. -## method: BrowserContext.cookies -- returns: <[Promise]<[Array]<[Object]>>> +## async method: BrowserContext.cookies +- returns: <[Array]<[Object]>> - `name` <[string]> - `value` <[string]> - `domain` <[string]> @@ -256,8 +256,7 @@ are returned. Optional list of URLs. -## method: BrowserContext.exposeBinding -- returns: <[Promise]> +## async method: BrowserContext.exposeBinding The method adds a function called `name` on the `window` object of every frame in every page in the context. When called, the function executes `playwrightBinding` in Node.js and returns a [Promise] which resolves to the return value @@ -322,8 +321,7 @@ Callback function that will be called in the Playwright's context. Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument is supported. When passing by value, multiple arguments are supported. -## method: BrowserContext.exposeFunction -- returns: <[Promise]> +## async method: BrowserContext.exposeFunction The method adds a function called `name` on the `window` object of every frame in every page in the context. When called, the function executes `playwrightFunction` in Node.js and returns a [Promise] which resolves to the return value @@ -367,8 +365,7 @@ Name of the function on the window object. Callback function that will be called in the Playwright's context. -## method: BrowserContext.grantPermissions -- returns: <[Promise]> +## async method: BrowserContext.grantPermissions Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin if specified. @@ -399,17 +396,17 @@ A permission or an array of permissions to grant. Permissions can be one of the The [origin] to grant permissions to, e.g. "https://example.com". -## method: BrowserContext.newPage -- returns: <[Promise]<[Page]>> +## async method: BrowserContext.newPage +- returns: <[Page]> Creates a new page in the browser context. ## method: 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()](). +- returns: <[Array]<[Page]>> -## method: BrowserContext.route -- returns: <[Promise]> +Returns 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()](). + +## async method: BrowserContext.route Routing provides the capability to modify network requests that are made by any page in the browser context. Once route is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted. @@ -479,8 +476,7 @@ This setting will change the default maximum time for all the methods accepting Maximum time in milliseconds -## method: BrowserContext.setExtraHTTPHeaders -- returns: <[Promise]> +## async method: BrowserContext.setExtraHTTPHeaders 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()](). If page overrides a particular header, @@ -493,8 +489,7 @@ page-specific header value will be used instead of the browser context header va An object containing additional HTTP headers to be sent with every request. All header values must be strings. -## method: BrowserContext.setGeolocation -- returns: <[Promise]> +## async method: BrowserContext.setGeolocation Sets the context's geolocation. Passing `null` or `undefined` emulates position unavailable. @@ -511,8 +506,7 @@ read its geolocation. - `longitude` <[number]> Longitude between -180 and 180. **required** - `accuracy` <[number]> Non-negative accuracy value. Defaults to `0`. -## method: BrowserContext.setHTTPCredentials -- returns: <[Promise]> +## async method: BrowserContext.setHTTPCredentials Provide credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication). @@ -525,16 +519,15 @@ instead. - `username` <[string]> **required** - `password` <[string]> **required** -## method: BrowserContext.setOffline -- returns: <[Promise]> +## async method: BrowserContext.setOffline ### param: BrowserContext.setOffline.offline - `offline` <[boolean]> Whether to emulate network being offline for the browser context. -## method: BrowserContext.storageState -- returns: <[Promise]<[Object]>> +## async method: BrowserContext.storageState +- returns: <[Object]> - `cookies` <[Array]<[Object]>> - `name` <[string]> - `value` <[string]> @@ -552,8 +545,7 @@ Whether to emulate network being offline for the browser context. Returns storage state for this browser context, contains current cookies and local storage snapshot. -## method: BrowserContext.unroute -- returns: <[Promise]> +## async method: BrowserContext.unroute Removes a route created with [browserContext.route()](). When `handler` is not specified, removes all routes for the `url`. @@ -568,11 +560,11 @@ A glob pattern, regex pattern or predicate receiving [URL] used to register a ro Optional handler function used to register a routing with [browserContext.route()](). -## method: BrowserContext.waitForEvent -- returns: <[Promise]<[Object]>> Promise which resolves to the event data value. +## async method: BrowserContext.waitForEvent +- returns: <[Object]> 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 is fired. +value. Will throw an error if the context closes before the event is fired. Returns the event data value. ```js const context = await browser.newContext(); @@ -587,9 +579,7 @@ Event name, same one would pass into `browserContext.on(event)`. ### param: BrowserContext.waitForEvent.optionsOrPredicate - `optionsOrPredicate` <[Function]|[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). + - `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). Either a predicate that receives an event or an options object. Optional. @@ -807,8 +797,8 @@ 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. -## method: Page.$ -- returns: <[Promise]<[null]|[ElementHandle]>> +## async method: Page.$ +- returns: <[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`. @@ -817,8 +807,8 @@ Shortcut for main frame's [frame.$()](). ### param: Page.$.selector = %%-query-selector-%% -## method: Page.$$ -- returns: <[Promise]<[Array]<[ElementHandle]>>> +## async method: Page.$$ +- returns: <[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 `[]`. @@ -827,11 +817,11 @@ Shortcut for main frame's [frame.$$()](). ### param: Page.$$.selector = %%-query-selector-%% -## method: Page.$eval -- returns: <[Promise]<[Serializable]>> Promise which resolves to the return value of `pageFunction` +## async method: Page.$eval +- returns: <[Serializable]> The method finds an element matching the specified selector within the page and passes it as a first argument to -`pageFunction`. If no elements match the selector, the method throws an error. +`pageFunction`. If no elements match the selector, the method throws an error. Returns the value of `pageFunction`. If `pageFunction` returns a [Promise], then `page.$eval` would wait for the promise to resolve and return its value. @@ -857,11 +847,11 @@ Function to be evaluated in browser context Optional argument to pass to `pageFunction` -## method: Page.$$eval -- returns: <[Promise]<[Serializable]>> Promise which resolves to the return value of `pageFunction` +## async method: Page.$$eval +- returns: <[Serializable]> 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`. +a first argument to `pageFunction`. Returns the result of `pageFunction` invocation. If `pageFunction` returns a [Promise], then `page.$$eval` would wait for the promise to resolve and return its value. @@ -886,13 +876,11 @@ Optional argument to pass to `pageFunction` ## namespace: Page.accessibility - returns: <[Accessibility]> -## method: Page.addInitScript -- returns: <[Promise]> +## async method: Page.addInitScript 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 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`. @@ -913,8 +901,7 @@ await page.addInitScript(preloadFile); ### param: Page.addInitScript.script - `script` <[function]|[string]|[Object]> - - `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). + - `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. Script to be evaluated in the page. @@ -924,53 +911,45 @@ Script to be evaluated in the page. Optional argument to pass to `script` (only supported when passing a function). -## method: Page.addScriptTag -- returns: <[Promise]<[ElementHandle]>> which resolves to the added tag when the script's onload fires or when the - script content was injected into frame. +## async method: Page.addScriptTag +- returns: <[ElementHandle]> -Adds a `