chore(docs): add comments to page.ts

* fix: modified comment for method product, platform and newPage

* fix: added comment for browsercontext, StartCSSCoverage, StartJSCoverage

* fix: corrected comments for JSONValue, asElement, evaluateHandle

* fix: corrected comments for JSONValue, asElement, evaluateHandle

* fix: added comments for some of the method

* fix: added proper comments

* fix: added comment for some methods in page.ts

* fix: rectified the comments

* fix: changed some of the comments

Co-authored-by: Jack Franklin <jacktfranklin@chromium.org>
This commit is contained in:
TASNEEM KOUSHAR 2021-06-02 18:17:20 +05:30 committed by GitHub
parent af83207176
commit 1108b63d82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -694,14 +694,14 @@ export class Page extends EventEmitter {
} }
/** /**
* @returns The browser this page belongs to. * Get the browser the page belongs to.
*/ */
browser(): Browser { browser(): Browser {
return this._target.browser(); return this._target.browser();
} }
/** /**
* @returns The browser context that the page belongs to * Get the browser context that the page belongs to.
*/ */
browserContext(): BrowserContext { browserContext(): BrowserContext {
return this._target.browserContext(); return this._target.browserContext();
@ -1085,12 +1085,27 @@ export class Page extends EventEmitter {
return this.mainFrame().$$eval<ReturnType>(selector, pageFunction, ...args); return this.mainFrame().$$eval<ReturnType>(selector, pageFunction, ...args);
} }
/**
* The method runs `document.querySelectorAll` within the page. If no elements
* match the selector, the return value resolves to `[]`.
* @remarks
* Shortcut for {@link Frame.$$ | Page.mainFrame().$$(selector) }.
* @param selector - A `selector` to query page for
*/
async $$<T extends Element = Element>( async $$<T extends Element = Element>(
selector: string selector: string
): Promise<Array<ElementHandle<T>>> { ): Promise<Array<ElementHandle<T>>> {
return this.mainFrame().$$<T>(selector); return this.mainFrame().$$<T>(selector);
} }
/**
* The method evaluates the XPath expression relative to the page document as
* its context node. If there are no such elements, the method resolves to an
* empty array.
* @remarks
* Shortcut for {@link Frame.$x | Page.mainFrame().$x(expression) }.
* @param expression - Expression to evaluate
*/
async $x(expression: string): Promise<ElementHandle[]> { async $x(expression: string): Promise<ElementHandle[]> {
return this.mainFrame().$x(expression); return this.mainFrame().$x(expression);
} }
@ -1148,6 +1163,13 @@ export class Page extends EventEmitter {
await this._client.send('Network.setCookies', { cookies: items }); await this._client.send('Network.setCookies', { cookies: items });
} }
/**
* Adds a `<script>` tag into the page with the desired URL or content.
* @remarks
* Shortcut for {@link Frame.addScriptTag | page.mainFrame().addScriptTag(options) }.
* @returns Promise which resolves to the added tag when the script's onload fires or
* when the script content was injected into frame.
*/
async addScriptTag(options: { async addScriptTag(options: {
url?: string; url?: string;
path?: string; path?: string;
@ -1157,6 +1179,12 @@ export class Page extends EventEmitter {
return this.mainFrame().addScriptTag(options); return this.mainFrame().addScriptTag(options);
} }
/**
* Adds a `<link rel="stylesheet">` tag into the page with the desired URL or a
* `<style type="text/css">` tag with the content.
* @returns Promise which resolves to the added tag when the stylesheet's
* onload fires or when the CSS content was injected into frame.
*/
async addStyleTag(options: { async addStyleTag(options: {
url?: string; url?: string;
path?: string; path?: string;
@ -1185,6 +1213,10 @@ export class Page extends EventEmitter {
); );
} }
/**
* Provide credentials for `HTTP authentication`.
* @remarks To disable authentication, pass `null`.
*/
async authenticate(credentials: Credentials): Promise<void> { async authenticate(credentials: Credentials): Promise<void> {
return this._frameManager.networkManager().authenticate(credentials); return this._frameManager.networkManager().authenticate(credentials);
} }
@ -1475,6 +1507,9 @@ export class Page extends EventEmitter {
return result[0]; return result[0];
} }
/**
* Brings page to front (activates tab).
*/
async bringToFront(): Promise<void> { async bringToFront(): Promise<void> {
await this._client.send('Page.bringToFront'); await this._client.send('Page.bringToFront');
} }
@ -1994,6 +2029,29 @@ export class Page extends EventEmitter {
return this._mouse; return this._mouse;
} }
/**
* This method fetches an element with `selector`, scrolls it into view if
* needed, and then uses {@link page.mouse} to click in the center of the
* element. If there's no element matching `selector`, the method throws an
* error.
* @remarks Bear in mind that if `click()` triggers a navigation event and
* there's a separate `page.waitForNavigation()` promise to be resolved, you
* may end up with a race condition that yields unexpected results. The
* correct pattern for click and wait for navigation is the following:
* ```js
* const [response] = await Promise.all([
* page.waitForNavigation(waitOptions),
* page.click(selector, clickOptions),
* ]);
* ```
* Shortcut for {@link Frame.click | page.mainFrame().click(selector[, options]) }.
* @param selector - A `selector` to search for element to click. If there are
* multiple elements satisfying the `selector`, the first will be clicked
* @param options - `Object`
* @returns Promise which resolves when the element matching `selector` is
* successfully clicked. The Promise will be rejected if there is no element
* matching `selector`.
*/
click( click(
selector: string, selector: string,
options: { options: {