mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore(docs): page.emulateVisionDeficiency
docs (#6231)
This commit also removes our own custom type for defining the vision deficiencies and uses the protocol's type. Now we generate docs for those we get the docs generated for free for these. This is better than us duplicating values for types in doc comments and having them become outdated. If we use the protocol types directly then we ensure we're up to date and in-sync. Long term the docs will also link to the devtools-protocol viewer.
This commit is contained in:
parent
e3933ddd82
commit
13f8fe6e16
@ -4,19 +4,46 @@
|
|||||||
|
|
||||||
## Page.emulateVisionDeficiency() method
|
## Page.emulateVisionDeficiency() method
|
||||||
|
|
||||||
|
Simulates the given vision deficiency on the page.
|
||||||
|
|
||||||
<b>Signature:</b>
|
<b>Signature:</b>
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
emulateVisionDeficiency(type?: VisionDeficiency): Promise<void>;
|
emulateVisionDeficiency(type?: Protocol.Emulation.SetEmulatedVisionDeficiencyRequest['type']): Promise<void>;
|
||||||
```
|
```
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| 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>
|
<b>Returns:</b>
|
||||||
|
|
||||||
Promise<void>
|
Promise<void>
|
||||||
|
|
||||||
|
## 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();
|
||||||
|
})();
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ page.off('request', logRequest);
|
|||||||
| [emulateMediaFeatures(features)](./puppeteer.page.emulatemediafeatures.md) | | |
|
| [emulateMediaFeatures(features)](./puppeteer.page.emulatemediafeatures.md) | | |
|
||||||
| [emulateMediaType(type)](./puppeteer.page.emulatemediatype.md) | | |
|
| [emulateMediaType(type)](./puppeteer.page.emulatemediatype.md) | | |
|
||||||
| [emulateTimezone(timezoneId)](./puppeteer.page.emulatetimezone.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) | | |
|
| [evaluate(pageFunction, args)](./puppeteer.page.evaluate.md) | | |
|
||||||
| [evaluateHandle(pageFunction, args)](./puppeteer.page.evaluatehandle.md) | | |
|
| [evaluateHandle(pageFunction, args)](./puppeteer.page.evaluatehandle.md) | | |
|
||||||
| [evaluateOnNewDocument(pageFunction, args)](./puppeteer.page.evaluateonnewdocument.md) | | |
|
| [evaluateOnNewDocument(pageFunction, args)](./puppeteer.page.evaluateonnewdocument.md) | | |
|
||||||
|
@ -152,14 +152,6 @@ interface ScreenshotOptions {
|
|||||||
encoding?: string;
|
encoding?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
type VisionDeficiency =
|
|
||||||
| 'none'
|
|
||||||
| 'achromatopsia'
|
|
||||||
| 'blurredVision'
|
|
||||||
| 'deuteranopia'
|
|
||||||
| 'protanopia'
|
|
||||||
| 'tritanopia';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All the events that a page instance may emit.
|
* All the events that a page instance may emit.
|
||||||
*
|
*
|
||||||
@ -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',
|
'none',
|
||||||
'achromatopsia',
|
'achromatopsia',
|
||||||
'blurredVision',
|
'blurredVision',
|
||||||
|
@ -653,7 +653,7 @@ function compareDocumentations(actual, expected) {
|
|||||||
'Method Page.emulateVisionDeficiency() type',
|
'Method Page.emulateVisionDeficiency() type',
|
||||||
{
|
{
|
||||||
actualName: 'string',
|
actualName: 'string',
|
||||||
expectedName: 'VisionDeficiency',
|
expectedName: 'Object',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
Loading…
Reference in New Issue
Block a user