How to use the puppeteer-core.devices function in puppeteer-core

To help you get started, we’ve selected a few puppeteer-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mbalabash / estimo / src / create-chrome-trace.js View on Github external
})
  const context = await browser.createIncognitoBrowserContext()

  // Set-up page entity
  const page = await context.newPage()
  if (options.userAgent) {
    await page.setUserAgent(options.userAgent)
  }
  if (options.width && options.height) {
    await page.setViewport({
      width: options.width,
      height: options.height,
    })
  }
  if (options.device) {
    if (puppeteer.devices[options.device]) {
      await page.emulate(puppeteer.devices[options.device])
    } else {
      throw new Error(`${options.device} - unknown Device option!`)
    }
  }
  page.on('error', msg => {
    throw msg
  })
  const client = await page.target().createCDPSession()

  // Enable Network Emulation
  if (options.emulateNetworkConditions) {
    await client.send('Network.emulateNetworkConditions', {
      offline: options.offline,
      latency: options.latency,
      downloadThroughput: megabitsToBytes(options.downloadThroughput),
github mbalabash / estimo / src / create-chrome-trace.js View on Github external
const context = await browser.createIncognitoBrowserContext()

  // Set-up page entity
  const page = await context.newPage()
  if (options.userAgent) {
    await page.setUserAgent(options.userAgent)
  }
  if (options.width && options.height) {
    await page.setViewport({
      width: options.width,
      height: options.height,
    })
  }
  if (options.device) {
    if (puppeteer.devices[options.device]) {
      await page.emulate(puppeteer.devices[options.device])
    } else {
      throw new Error(`${options.device} - unknown Device option!`)
    }
  }
  page.on('error', msg => {
    throw msg
  })
  const client = await page.target().createCDPSession()

  // Enable Network Emulation
  if (options.emulateNetworkConditions) {
    await client.send('Network.emulateNetworkConditions', {
      offline: options.offline,
      latency: options.latency,
      downloadThroughput: megabitsToBytes(options.downloadThroughput),
      uploadThroughput: megabitsToBytes(options.uploadThroughput),