emulate method

Future<void> emulate(
  1. Device device
)

Emulates given device metrics and user agent. This method is a shortcut for calling two methods:

To aid emulation, puppeteer provides a list of device descriptors which can be obtained via the 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.

var iPhone = puppeteer.devices.iPhone6;

var browser = await puppeteer.launch();
var page = await browser.newPage();
await page.emulate(iPhone);
await page.goto('https://example.com');
// other actions...
await browser.close();

List of all available devices is available in the source code: devices.dart.

Implementation

Future<void> emulate(Device device) async {
  await setViewport(device.viewport);
  await setUserAgent(device.userAgent(
      (await devTools.browser.getVersion()).product.split('/').last));
}