How to use the puppeteer.devices function in puppeteer

To help you get started, we’ve selected a few puppeteer 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 337547038 / Automated-build-tools-for-front-end / guilin / lib / htmlhint.js View on Github external
/**
 * Created by 337547038
 * 2019
 * https://github.com/337547038/Automated-build-tools-for-front-end
 */
const fs = require('fs');
const htmlhint = require("htmlhint");
// https://github.com/htmlhint/HTMLHint/wiki/Usage
const puppeteer = require('puppeteer');
// https://github.com/GoogleChrome/puppeteer/blob/master/lib/DeviceDescriptors.js
const iPhone = puppeteer.devices['iPhone X'];
let pass = true;
let timer = '';
let config = {};
let tempHtml = [];

const searchHtmlFiles = async function () {
  // const stratTime = new Date()
  console.time('usedTime');
  config = JSON.parse(fs.readFileSync('./package.json'));
  console.log(`Check path ./${config.dist}, Please wait...`);
  searchHtml(config.dist);
  if (config.codeCheck.screenshots) {
    console.log('Saving screenshots...');
    const savePath = config.dist + '/screenshots';
    if (!fs.existsSync(savePath)) {
      fs.mkdirSync(savePath)
github gramener / gramex / gramex / apps / capture / chromecapture.js View on Github external
// Clear past cookies
  let cookies = await page.cookies(q.url)
  await page.deleteCookie(...cookies)
  // Parse cookies and set them on the page, so that they'll be sent on any
  // requests to this URL. (This overrides the request HTTP header "Cookie")
  if (q.cookie) {
    let cookieList = []
    let cookieObj = cookie.parse(q.cookie)
    for (let key in cookieObj)
      cookieList.push({name: key, value: cookieObj[key], url: q.url})
    await page.setCookie(...cookieList)
    delete headers.cookie
  }

  if (q.emulate) {
    let device = Object.assign({}, puppeteer.devices[q.emulate])
    device.viewport.deviceScaleFactor = +q.scale || device.viewport.deviceScaleFactor
    await page.emulate(device)
  } else {
    await page.setViewport({
      width: +q.width || 1200,
      height: +q.height || 768,
      deviceScaleFactor: +q.scale || 1    // Apply for PDF?
    })
  }

  // Set additional HTTP headers
  ignore_headers.forEach(function (header) { delete headers[header] })
  await page.setExtraHTTPHeaders(headers)

  await page.goto(q.url)
github spatie / browsershot / bin / browser.js View on Github external
request.continue();
            });
        }

        if (request.options && request.options.dismissDialogs) {
            page.on('dialog', async dialog => {
                await dialog.dismiss();
            });
        }

        if (request.options && request.options.userAgent) {
            await page.setUserAgent(request.options.userAgent);
        }

        if (request.options && request.options.device) {
            const devices = puppeteer.devices;
            const device = devices[request.options.device];
            await page.emulate(device);
        }

        if (request.options && request.options.emulateMedia) {
            await page.emulateMediaType(request.options.emulateMedia);
        }

        if (request.options && request.options.viewport) {
            await page.setViewport(request.options.viewport);
        }

        if (request.options && request.options.extraHTTPHeaders) {
            await page.setExtraHTTPHeaders(request.options.extraHTTPHeaders);
        }