Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): page.emulateVisionDeficiency docs #6231

Merged
merged 1 commit into from Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 29 additions & 2 deletions new-docs/puppeteer.page.emulatevisiondeficiency.md
Expand Up @@ -4,19 +4,46 @@

## Page.emulateVisionDeficiency() method

Simulates the given vision deficiency on the page.

<b>Signature:</b>

```typescript
emulateVisionDeficiency(type?: VisionDeficiency): Promise<void>;
emulateVisionDeficiency(type?: Protocol.Emulation.SetEmulatedVisionDeficiencyRequest['type']): Promise<void>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| type | VisionDeficiency | |
| type | [Protocol.Emulation.SetEmulatedVisionDeficiencyRequest](./puppeteer.protocol.emulation.setemulatedvisiondeficiencyrequest.md)<!-- -->\['type'\] | the type of deficiency to simulate, or <code>'none'</code> to reset. |

<b>Returns:</b>

Promise&lt;void&gt;

## Example


```js
const puppeteer = require('puppeteer');

(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://v8.dev/blog/10-years');

await page.emulateVisionDeficiency('achromatopsia');
await page.screenshot({ path: 'achromatopsia.png' });

await page.emulateVisionDeficiency('deuteranopia');
await page.screenshot({ path: 'deuteranopia.png' });

await page.emulateVisionDeficiency('blurredVision');
await page.screenshot({ path: 'blurred-vision.png' });

await browser.close();
})();

```

2 changes: 1 addition & 1 deletion new-docs/puppeteer.page.md
Expand Up @@ -92,7 +92,7 @@ page.off('request', logRequest);
| [emulateMediaFeatures(features)](./puppeteer.page.emulatemediafeatures.md) | | |
| [emulateMediaType(type)](./puppeteer.page.emulatemediatype.md) | | |
| [emulateTimezone(timezoneId)](./puppeteer.page.emulatetimezone.md) | | |
| [emulateVisionDeficiency(type)](./puppeteer.page.emulatevisiondeficiency.md) | | |
| [emulateVisionDeficiency(type)](./puppeteer.page.emulatevisiondeficiency.md) | | Simulates the given vision deficiency on the page. |
| [evaluate(pageFunction, args)](./puppeteer.page.evaluate.md) | | |
| [evaluateHandle(pageFunction, args)](./puppeteer.page.evaluatehandle.md) | | |
| [evaluateOnNewDocument(pageFunction, args)](./puppeteer.page.evaluateonnewdocument.md) | | |
Expand Down
43 changes: 33 additions & 10 deletions src/common/Page.ts
Expand Up @@ -152,14 +152,6 @@ interface ScreenshotOptions {
encoding?: string;
}

type VisionDeficiency =
| 'none'
| 'achromatopsia'
| 'blurredVision'
| 'deuteranopia'
| 'protanopia'
| 'tritanopia';

/**
* All the events that a page instance may emit.
*
Expand Down Expand Up @@ -1451,8 +1443,39 @@ export class Page extends EventEmitter {
}
}

async emulateVisionDeficiency(type?: VisionDeficiency): Promise<void> {
const visionDeficiencies = new Set([
/**
* Simulates the given vision deficiency on the page.
*
* @example
* ```js
* const puppeteer = require('puppeteer');
*
* (async () => {
* const browser = await puppeteer.launch();
* const page = await browser.newPage();
* await page.goto('https://v8.dev/blog/10-years');
*
* await page.emulateVisionDeficiency('achromatopsia');
* await page.screenshot({ path: 'achromatopsia.png' });
*
* await page.emulateVisionDeficiency('deuteranopia');
* await page.screenshot({ path: 'deuteranopia.png' });
*
* await page.emulateVisionDeficiency('blurredVision');
* await page.screenshot({ path: 'blurred-vision.png' });
*
* await browser.close();
* })();
* ```
*
* @param type - the type of deficiency to simulate, or `'none'` to reset.
*/
async emulateVisionDeficiency(
type?: Protocol.Emulation.SetEmulatedVisionDeficiencyRequest['type']
): Promise<void> {
const visionDeficiencies = new Set<
Protocol.Emulation.SetEmulatedVisionDeficiencyRequest['type']
>([
'none',
'achromatopsia',
'blurredVision',
Expand Down
2 changes: 1 addition & 1 deletion utils/doclint/check_public_api/index.js
Expand Up @@ -653,7 +653,7 @@ function compareDocumentations(actual, expected) {
'Method Page.emulateVisionDeficiency() type',
{
actualName: 'string',
expectedName: 'VisionDeficiency',
expectedName: 'Object',
},
],
[
Expand Down