chore(docs): comments for page methods

* 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

* fix: added comments for 3 more methods of class page

* fix: added comments for 3 more methods of class page

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

View File

@ -1514,6 +1514,29 @@ export class Page extends EventEmitter {
await this._client.send('Page.bringToFront'); await this._client.send('Page.bringToFront');
} }
/**
* Emulates given device metrics and user agent. This method is a shortcut for
* calling two methods: {@link page.setUserAgent} and {@link page.setViewport}
* To aid emulation, Puppeteer provides a list of device descriptors that can
* be obtained via the {@link puppeteer.devices} `page.emulate` will resize
* the page. A lot of websites don't expect phones to change size, so you
* should emulate before navigating to the page.
* @example
* ```js
* const puppeteer = require('puppeteer');
* const iPhone = puppeteer.devices['iPhone 6'];
* (async () => {
* const browser = await puppeteer.launch();
* const page = await browser.newPage();
* await page.emulate(iPhone);
* await page.goto('https://www.google.com');
* // other actions...
* await browser.close();
* })();
* ```
* @remarks List of all available devices is available in the source code:
* {@link https://github.com/puppeteer/puppeteer/blob/main/src/common/DeviceDescriptors.ts | src/common/DeviceDescriptors.ts}.
*/
async emulate(options: { async emulate(options: {
viewport: Viewport; viewport: Viewport;
userAgent: string; userAgent: string;
@ -1546,6 +1569,58 @@ export class Page extends EventEmitter {
}); });
} }
/**
* @param features - `<?Array<Object>>` Given an array of media feature
* objects, emulates CSS media features on the page. Each media feature object
* must have the following properties:
* @example
* ```js
* await page.emulateMediaFeatures([
* { name: 'prefers-color-scheme', value: 'dark' },
* ]);
* await page.evaluate(() => matchMedia('(prefers-color-scheme: dark)').matches);
* // → true
* await page.evaluate(() => matchMedia('(prefers-color-scheme: light)').matches);
* // → false
*
* await page.emulateMediaFeatures([
* { name: 'prefers-reduced-motion', value: 'reduce' },
* ]);
* await page.evaluate(
* () => matchMedia('(prefers-reduced-motion: reduce)').matches
* );
* // → true
* await page.evaluate(
* () => matchMedia('(prefers-reduced-motion: no-preference)').matches
* );
* // → false
*
* await page.emulateMediaFeatures([
* { name: 'prefers-color-scheme', value: 'dark' },
* { name: 'prefers-reduced-motion', value: 'reduce' },
* ]);
* await page.evaluate(() => matchMedia('(prefers-color-scheme: dark)').matches);
* // → true
* await page.evaluate(() => matchMedia('(prefers-color-scheme: light)').matches);
* // → false
* await page.evaluate(
* () => matchMedia('(prefers-reduced-motion: reduce)').matches
* );
* // → true
* await page.evaluate(
* () => matchMedia('(prefers-reduced-motion: no-preference)').matches
* );
* // → false
*
* await page.emulateMediaFeatures([{ name: 'color-gamut', value: 'p3' }]);
* await page.evaluate(() => matchMedia('(color-gamut: srgb)').matches);
* // → true
* await page.evaluate(() => matchMedia('(color-gamut: p3)').matches);
* // → true
* await page.evaluate(() => matchMedia('(color-gamut: rec2020)').matches);
* // → false
* ```
*/
async emulateMediaFeatures(features?: MediaFeature[]): Promise<void> { async emulateMediaFeatures(features?: MediaFeature[]): Promise<void> {
if (features === null) if (features === null)
await this._client.send('Emulation.setEmulatedMedia', { features: null }); await this._client.send('Emulation.setEmulatedMedia', { features: null });
@ -1595,8 +1670,6 @@ export class Page extends EventEmitter {
* ``` * ```
* *
* @param overrides - Mock idle state. If not set, clears idle overrides * @param overrides - Mock idle state. If not set, clears idle overrides
* @param isUserActive - Mock isUserActive
* @param isScreenUnlocked - Mock isScreenUnlocked
*/ */
async emulateIdleState(overrides?: { async emulateIdleState(overrides?: {
isUserActive: boolean; isUserActive: boolean;