page.emulate(options)
. Actual list of devices can be found in [src/common/DeviceDescriptors.ts](https://github.com/puppeteer/puppeteer/blob/main/src/common/DeviceDescriptors.ts). |
-| [errors](./puppeteer.errors.md) | |
-| [EVALUATION_SCRIPT_URL](./puppeteer.evaluation_script_url.md) | |
-| [executablePath](./puppeteer.executablepath.md) | |
-| [launch](./puppeteer.launch.md) | |
-| [networkConditions](./puppeteer.networkconditions.md) | |
-| [PredefinedNetworkConditions](./puppeteer.predefinednetworkconditions.md) | A list of network conditions to be used with [Page.emulateNetworkConditions()](./puppeteer.page.emulatenetworkconditions.md). |
+| Variable | Description |
+| --------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
+| [connect](./puppeteer.connect.md) | |
+| [createBrowserFetcher](./puppeteer.createbrowserfetcher.md) | |
+| [DEFAULT_INTERCEPT_RESOLUTION_PRIORITY](./puppeteer.default_intercept_resolution_priority.md) | The default cooperative request interception resolution priority |
+| [defaultArgs](./puppeteer.defaultargs.md) | |
+| [devices](./puppeteer.devices.md) | |
+| [errors](./puppeteer.errors.md) | |
+| [EVALUATION_SCRIPT_URL](./puppeteer.evaluation_script_url.md) | |
+| [executablePath](./puppeteer.executablepath.md) | |
+| [KnownDevices](./puppeteer.knowndevices.md) | A list of devices to be used with [Page.emulate()](./puppeteer.page.emulate.md). |
+| [launch](./puppeteer.launch.md) | |
+| [networkConditions](./puppeteer.networkconditions.md) | |
+| [PredefinedNetworkConditions](./puppeteer.predefinednetworkconditions.md) | A list of network conditions to be used with [Page.emulateNetworkConditions()](./puppeteer.page.emulatenetworkconditions.md). |
## Type Aliases
@@ -142,7 +143,6 @@ sidebar_label: API
| [Awaitable](./puppeteer.awaitable.md) | |
| [ChromeReleaseChannel](./puppeteer.chromereleasechannel.md) | |
| [ConsoleMessageType](./puppeteer.consolemessagetype.md) | The supported types for console messages. |
-| [DevicesMap](./puppeteer.devicesmap.md) | |
| [ErrorCode](./puppeteer.errorcode.md) | |
| [EvaluateFunc](./puppeteer.evaluatefunc.md) | |
| [EventType](./puppeteer.eventtype.md) | |
diff --git a/docs/api/puppeteer.device.md b/docs/api/puppeteer.device.md
index f284e7b0924..d2ccae149d2 100644
--- a/docs/api/puppeteer.device.md
+++ b/docs/api/puppeteer.device.md
@@ -12,8 +12,7 @@ export interface Device
## Properties
-| Property | Modifiers | Type | Description |
-| -------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------- | ----------- |
-| [name](./puppeteer.device.name.md) | | string | |
-| [userAgent](./puppeteer.device.useragent.md) | | string | |
-| [viewport](./puppeteer.device.viewport.md) | | { width: number; height: number; deviceScaleFactor: number; isMobile: boolean; hasTouch: boolean; isLandscape: boolean; } | |
+| Property | Modifiers | Type | Description |
+| -------------------------------------------- | --------- | ----------------------------------- | ----------- |
+| [userAgent](./puppeteer.device.useragent.md) | | string | |
+| [viewport](./puppeteer.device.viewport.md) | | [Viewport](./puppeteer.viewport.md) | |
diff --git a/docs/api/puppeteer.device.name.md b/docs/api/puppeteer.device.name.md
deleted file mode 100644
index 467a6bd1a1f..00000000000
--- a/docs/api/puppeteer.device.name.md
+++ /dev/null
@@ -1,13 +0,0 @@
----
-sidebar_label: Device.name
----
-
-# Device.name property
-
-**Signature:**
-
-```typescript
-interface Device {
- name: string;
-}
-```
diff --git a/docs/api/puppeteer.device.viewport.md b/docs/api/puppeteer.device.viewport.md
index 5b3e8bd0488..ba1048132ca 100644
--- a/docs/api/puppeteer.device.viewport.md
+++ b/docs/api/puppeteer.device.viewport.md
@@ -8,13 +8,6 @@ sidebar_label: Device.viewport
```typescript
interface Device {
- viewport: {
- width: number;
- height: number;
- deviceScaleFactor: number;
- isMobile: boolean;
- hasTouch: boolean;
- isLandscape: boolean;
- };
+ viewport: Viewport;
}
```
diff --git a/docs/api/puppeteer.devices.md b/docs/api/puppeteer.devices.md
index 8b688a4f1b1..72cc7667e1b 100644
--- a/docs/api/puppeteer.devices.md
+++ b/docs/api/puppeteer.devices.md
@@ -4,26 +4,131 @@ sidebar_label: devices
# devices variable
-A list of devices to be used with `page.emulate(options)`. Actual list of devices can be found in [src/common/DeviceDescriptors.ts](https://github.com/puppeteer/puppeteer/blob/main/src/common/DeviceDescriptors.ts).
+> Warning: This API is now obsolete.
+>
+> Import [KnownDevices](./puppeteer.knowndevices.md)
**Signature:**
```typescript
-devices: DevicesMap;
-```
-
-## Example
-
-```ts
-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();
-})();
+devices: Readonly<
+ Record<
+ | 'Blackberry PlayBook'
+ | 'Blackberry PlayBook landscape'
+ | 'BlackBerry Z30'
+ | 'BlackBerry Z30 landscape'
+ | 'Galaxy Note 3'
+ | 'Galaxy Note 3 landscape'
+ | 'Galaxy Note II'
+ | 'Galaxy Note II landscape'
+ | 'Galaxy S III'
+ | 'Galaxy S III landscape'
+ | 'Galaxy S5'
+ | 'Galaxy S5 landscape'
+ | 'Galaxy S8'
+ | 'Galaxy S8 landscape'
+ | 'Galaxy S9+'
+ | 'Galaxy S9+ landscape'
+ | 'Galaxy Tab S4'
+ | 'Galaxy Tab S4 landscape'
+ | 'iPad'
+ | 'iPad landscape'
+ | 'iPad (gen 6)'
+ | 'iPad (gen 6) landscape'
+ | 'iPad (gen 7)'
+ | 'iPad (gen 7) landscape'
+ | 'iPad Mini'
+ | 'iPad Mini landscape'
+ | 'iPad Pro'
+ | 'iPad Pro landscape'
+ | 'iPad Pro 11'
+ | 'iPad Pro 11 landscape'
+ | 'iPhone 4'
+ | 'iPhone 4 landscape'
+ | 'iPhone 5'
+ | 'iPhone 5 landscape'
+ | 'iPhone 6'
+ | 'iPhone 6 landscape'
+ | 'iPhone 6 Plus'
+ | 'iPhone 6 Plus landscape'
+ | 'iPhone 7'
+ | 'iPhone 7 landscape'
+ | 'iPhone 7 Plus'
+ | 'iPhone 7 Plus landscape'
+ | 'iPhone 8'
+ | 'iPhone 8 landscape'
+ | 'iPhone 8 Plus'
+ | 'iPhone 8 Plus landscape'
+ | 'iPhone SE'
+ | 'iPhone SE landscape'
+ | 'iPhone X'
+ | 'iPhone X landscape'
+ | 'iPhone XR'
+ | 'iPhone XR landscape'
+ | 'iPhone 11'
+ | 'iPhone 11 landscape'
+ | 'iPhone 11 Pro'
+ | 'iPhone 11 Pro landscape'
+ | 'iPhone 11 Pro Max'
+ | 'iPhone 11 Pro Max landscape'
+ | 'iPhone 12'
+ | 'iPhone 12 landscape'
+ | 'iPhone 12 Pro'
+ | 'iPhone 12 Pro landscape'
+ | 'iPhone 12 Pro Max'
+ | 'iPhone 12 Pro Max landscape'
+ | 'iPhone 12 Mini'
+ | 'iPhone 12 Mini landscape'
+ | 'iPhone 13'
+ | 'iPhone 13 landscape'
+ | 'iPhone 13 Pro'
+ | 'iPhone 13 Pro landscape'
+ | 'iPhone 13 Pro Max'
+ | 'iPhone 13 Pro Max landscape'
+ | 'iPhone 13 Mini'
+ | 'iPhone 13 Mini landscape'
+ | 'JioPhone 2'
+ | 'JioPhone 2 landscape'
+ | 'Kindle Fire HDX'
+ | 'Kindle Fire HDX landscape'
+ | 'LG Optimus L70'
+ | 'LG Optimus L70 landscape'
+ | 'Microsoft Lumia 550'
+ | 'Microsoft Lumia 950'
+ | 'Microsoft Lumia 950 landscape'
+ | 'Nexus 10'
+ | 'Nexus 10 landscape'
+ | 'Nexus 4'
+ | 'Nexus 4 landscape'
+ | 'Nexus 5'
+ | 'Nexus 5 landscape'
+ | 'Nexus 5X'
+ | 'Nexus 5X landscape'
+ | 'Nexus 6'
+ | 'Nexus 6 landscape'
+ | 'Nexus 6P'
+ | 'Nexus 6P landscape'
+ | 'Nexus 7'
+ | 'Nexus 7 landscape'
+ | 'Nokia Lumia 520'
+ | 'Nokia Lumia 520 landscape'
+ | 'Nokia N9'
+ | 'Nokia N9 landscape'
+ | 'Pixel 2'
+ | 'Pixel 2 landscape'
+ | 'Pixel 2 XL'
+ | 'Pixel 2 XL landscape'
+ | 'Pixel 3'
+ | 'Pixel 3 landscape'
+ | 'Pixel 4'
+ | 'Pixel 4 landscape'
+ | 'Pixel 4a (5G)'
+ | 'Pixel 4a (5G) landscape'
+ | 'Pixel 5'
+ | 'Pixel 5 landscape'
+ | 'Moto G4'
+ | 'Moto G4 landscape',
+ Device
+ >
+>;
```
diff --git a/docs/api/puppeteer.devicesmap.md b/docs/api/puppeteer.devicesmap.md
deleted file mode 100644
index ec2b4a3da02..00000000000
--- a/docs/api/puppeteer.devicesmap.md
+++ /dev/null
@@ -1,15 +0,0 @@
----
-sidebar_label: DevicesMap
----
-
-# DevicesMap type
-
-**Signature:**
-
-```typescript
-export declare type DevicesMap = {
- [name: string]: Device;
-};
-```
-
-**References:** [Device](./puppeteer.device.md)
diff --git a/docs/api/puppeteer.knowndevices.md b/docs/api/puppeteer.knowndevices.md
new file mode 100644
index 00000000000..018e0b84dad
--- /dev/null
+++ b/docs/api/puppeteer.knowndevices.md
@@ -0,0 +1,148 @@
+---
+sidebar_label: KnownDevices
+---
+
+# KnownDevices variable
+
+A list of devices to be used with [Page.emulate()](./puppeteer.page.emulate.md).
+
+**Signature:**
+
+```typescript
+KnownDevices: Readonly<
+ Record<
+ | 'Blackberry PlayBook'
+ | 'Blackberry PlayBook landscape'
+ | 'BlackBerry Z30'
+ | 'BlackBerry Z30 landscape'
+ | 'Galaxy Note 3'
+ | 'Galaxy Note 3 landscape'
+ | 'Galaxy Note II'
+ | 'Galaxy Note II landscape'
+ | 'Galaxy S III'
+ | 'Galaxy S III landscape'
+ | 'Galaxy S5'
+ | 'Galaxy S5 landscape'
+ | 'Galaxy S8'
+ | 'Galaxy S8 landscape'
+ | 'Galaxy S9+'
+ | 'Galaxy S9+ landscape'
+ | 'Galaxy Tab S4'
+ | 'Galaxy Tab S4 landscape'
+ | 'iPad'
+ | 'iPad landscape'
+ | 'iPad (gen 6)'
+ | 'iPad (gen 6) landscape'
+ | 'iPad (gen 7)'
+ | 'iPad (gen 7) landscape'
+ | 'iPad Mini'
+ | 'iPad Mini landscape'
+ | 'iPad Pro'
+ | 'iPad Pro landscape'
+ | 'iPad Pro 11'
+ | 'iPad Pro 11 landscape'
+ | 'iPhone 4'
+ | 'iPhone 4 landscape'
+ | 'iPhone 5'
+ | 'iPhone 5 landscape'
+ | 'iPhone 6'
+ | 'iPhone 6 landscape'
+ | 'iPhone 6 Plus'
+ | 'iPhone 6 Plus landscape'
+ | 'iPhone 7'
+ | 'iPhone 7 landscape'
+ | 'iPhone 7 Plus'
+ | 'iPhone 7 Plus landscape'
+ | 'iPhone 8'
+ | 'iPhone 8 landscape'
+ | 'iPhone 8 Plus'
+ | 'iPhone 8 Plus landscape'
+ | 'iPhone SE'
+ | 'iPhone SE landscape'
+ | 'iPhone X'
+ | 'iPhone X landscape'
+ | 'iPhone XR'
+ | 'iPhone XR landscape'
+ | 'iPhone 11'
+ | 'iPhone 11 landscape'
+ | 'iPhone 11 Pro'
+ | 'iPhone 11 Pro landscape'
+ | 'iPhone 11 Pro Max'
+ | 'iPhone 11 Pro Max landscape'
+ | 'iPhone 12'
+ | 'iPhone 12 landscape'
+ | 'iPhone 12 Pro'
+ | 'iPhone 12 Pro landscape'
+ | 'iPhone 12 Pro Max'
+ | 'iPhone 12 Pro Max landscape'
+ | 'iPhone 12 Mini'
+ | 'iPhone 12 Mini landscape'
+ | 'iPhone 13'
+ | 'iPhone 13 landscape'
+ | 'iPhone 13 Pro'
+ | 'iPhone 13 Pro landscape'
+ | 'iPhone 13 Pro Max'
+ | 'iPhone 13 Pro Max landscape'
+ | 'iPhone 13 Mini'
+ | 'iPhone 13 Mini landscape'
+ | 'JioPhone 2'
+ | 'JioPhone 2 landscape'
+ | 'Kindle Fire HDX'
+ | 'Kindle Fire HDX landscape'
+ | 'LG Optimus L70'
+ | 'LG Optimus L70 landscape'
+ | 'Microsoft Lumia 550'
+ | 'Microsoft Lumia 950'
+ | 'Microsoft Lumia 950 landscape'
+ | 'Nexus 10'
+ | 'Nexus 10 landscape'
+ | 'Nexus 4'
+ | 'Nexus 4 landscape'
+ | 'Nexus 5'
+ | 'Nexus 5 landscape'
+ | 'Nexus 5X'
+ | 'Nexus 5X landscape'
+ | 'Nexus 6'
+ | 'Nexus 6 landscape'
+ | 'Nexus 6P'
+ | 'Nexus 6P landscape'
+ | 'Nexus 7'
+ | 'Nexus 7 landscape'
+ | 'Nokia Lumia 520'
+ | 'Nokia Lumia 520 landscape'
+ | 'Nokia N9'
+ | 'Nokia N9 landscape'
+ | 'Pixel 2'
+ | 'Pixel 2 landscape'
+ | 'Pixel 2 XL'
+ | 'Pixel 2 XL landscape'
+ | 'Pixel 3'
+ | 'Pixel 3 landscape'
+ | 'Pixel 4'
+ | 'Pixel 4 landscape'
+ | 'Pixel 4a (5G)'
+ | 'Pixel 4a (5G) landscape'
+ | 'Pixel 5'
+ | 'Pixel 5 landscape'
+ | 'Moto G4'
+ | 'Moto G4 landscape',
+ Device
+ >
+>;
+```
+
+## Example
+
+```ts
+import {KnownDevices} from 'puppeteer';
+const iPhone = KnownDevices['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();
+})();
+```
diff --git a/docs/api/puppeteer.page.emulate.md b/docs/api/puppeteer.page.emulate.md
index b365ff32c2f..32bf0edd519 100644
--- a/docs/api/puppeteer.page.emulate.md
+++ b/docs/api/puppeteer.page.emulate.md
@@ -4,21 +4,23 @@ sidebar_label: Page.emulate
# Page.emulate() method
-Emulates given device metrics and user agent.
+Emulates a given device's metrics and user agent.
+
+To aid emulation, Puppeteer provides a list of known devices that can be via [KnownDevices](./puppeteer.knowndevices.md).
**Signature:**
```typescript
class Page {
- emulate(options: {viewport: Viewport; userAgent: string}): Promiseprint
CSS media type. |
| [deleteCookie(cookies)](./puppeteer.page.deletecookie.md) | | |
-| [emulate(options)](./puppeteer.page.emulate.md) | | Emulates given device metrics and user agent. |
+| [emulate(device)](./puppeteer.page.emulate.md) | | Emulates a given device's metrics and user agent.
To aid emulation, Puppeteer provides a list of known devices that can be via [KnownDevices](./puppeteer.knowndevices.md).
| | [emulateCPUThrottling(factor)](./puppeteer.page.emulatecputhrottling.md) | | Enables CPU throttling to emulate slow CPUs. | | [emulateIdleState(overrides)](./puppeteer.page.emulateidlestate.md) | | Emulates the idle state. If no arguments set, clears idle state emulation. | | [emulateMediaFeatures(features)](./puppeteer.page.emulatemediafeatures.md) | | | diff --git a/docs/api/puppeteer.puppeteer.devices.md b/docs/api/puppeteer.puppeteer.devices.md deleted file mode 100644 index 6301dc04c09..00000000000 --- a/docs/api/puppeteer.puppeteer.devices.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -sidebar_label: Puppeteer.devices ---- - -# Puppeteer.devices property - -> Warning: This API is now obsolete. -> -> Import directly puppeteer. - -**Signature:** - -```typescript -class Puppeteer { - get devices(): typeof devices; -} -``` - -## Example - -```ts -import {devices} from 'puppeteer'; -``` diff --git a/docs/api/puppeteer.puppeteer.md b/docs/api/puppeteer.puppeteer.md index a9e9c7d70f5..3ede0dcafd8 100644 --- a/docs/api/puppeteer.puppeteer.md +++ b/docs/api/puppeteer.puppeteer.md @@ -18,12 +18,6 @@ export declare class Puppeteer The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `Puppeteer` class. -## Properties - -| Property | Modifiers | Type | Description | -| ------------------------------------------- | --------------------- | ---------------------------------------- | ----------- | -| [devices](./puppeteer.puppeteer.devices.md) |readonly
| typeof [devices](./puppeteer.devices.md) | |
-
## Methods
| Method | Modifiers | Description |
diff --git a/packages/puppeteer-core/src/api/Page.ts b/packages/puppeteer-core/src/api/Page.ts
index 6c45c981cdc..b1dfd6a7268 100644
--- a/packages/puppeteer-core/src/api/Page.ts
+++ b/packages/puppeteer-core/src/api/Page.ts
@@ -17,9 +17,9 @@
import {Protocol} from 'devtools-protocol';
import type {Readable} from 'stream';
import type {Accessibility} from '../common/Accessibility.js';
-import type {Browser, BrowserContext} from './Browser.js';
import type {ConsoleMessage} from '../common/ConsoleMessage.js';
import type {Coverage} from '../common/Coverage.js';
+import {Device} from '../common/Device.js';
import type {Dialog} from '../common/Dialog.js';
import type {ElementHandle} from '../common/ElementHandle.js';
import {EventEmitter, Handler} from '../common/EventEmitter.js';
@@ -48,6 +48,7 @@ import type {Target} from '../common/Target.js';
import type {Tracing} from '../common/Tracing.js';
import type {EvaluateFunc, HandleFor, NodeFor} from '../common/types.js';
import type {WebWorker} from '../common/WebWorker.js';
+import type {Browser, BrowserContext} from './Browser.js';
/**
* @public
@@ -1656,20 +1657,25 @@ export class Page extends EventEmitter {
}
/**
- * Emulates given device metrics and user agent.
+ * Emulates a given device's metrics and user agent.
+ *
+ * To aid emulation, Puppeteer provides a list of known devices that can be
+ * via {@link KnownDevices}.
*
* @remarks
* 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
- * {@link 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.
+ * {@link Page.setUserAgent} and {@link Page.setViewport}.
+ *
+ * @remarks
+ * This method 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
*
* ```ts
- * const puppeteer = require('puppeteer');
- * const iPhone = puppeteer.devices['iPhone 6'];
+ * import {KnownDevices} from 'puppeteer';
+ * const iPhone = KnownDevices['iPhone 6'];
+ *
* (async () => {
* const browser = await puppeteer.launch();
* const page = await browser.newPage();
@@ -1679,21 +1685,16 @@ export class Page extends EventEmitter {
* 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: {
- viewport: Viewport;
- userAgent: string;
- }): Promise