mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
87c08fd86a
This PR removes the deprecated `puppeteer.devices` in favor of a new exported object `KnownDevices`. `devices` can also be exported, but has been deprecated.
1.0 KiB
1.0 KiB
sidebar_label |
---|
Page.emulate |
Page.emulate() method
Emulates a given device's metrics and user agent.
To aid emulation, Puppeteer provides a list of known devices that can be via KnownDevices.
Signature:
class Page {
emulate(device: Device): Promise<void>;
}
Parameters
Parameter | Type | Description |
---|---|---|
device | Device |
Returns:
Promise<void>
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
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();
})();