How to use the puppeteer/DeviceDescriptors.length 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 umpox / generateDeviceScreenshots / index.js View on Github external
//Check user has provided enough information
if (process.argv.length <= 2 || inputtedURL === undefined || selectedDevices === undefined) {
    console.log('Incorrect Usage. Please use the following format:\n npm run generate-screenshots https://www.google.com "iPhone 6, iPhone 5"');
    process.exit(1);
}

//Check for screenshots folder, if not found then create it
const dir = './generated-screenshots';
if (!fs.existsSync(dir)){
    console.log(`Creating folder ${dir}...`);
    fs.mkdirSync(dir);
}

//Handle device input
if ( selectedDevices === "all" ) {
    numImages = devices.length;
} else {
    selectedDevices = selectedDevices.split(/,\s*/);
    numImages = selectedDevices.length;
}

//Handle modifier input
for (let modifier in modifiers) {
    switch (modifiers[modifier]) {
        case 'fullscreen':
            fullScreenStatus = true;
            break;
        case 'force-yes':
            forceYes = true;
            break;
        default:
            console.log(`Incorrect modifier provided: ${modifiers[modifier]}`);
github eugeniosegala / snap-this / index.js View on Github external
const snapThis = async () => {

  console.log('Starting...');

  const browser = await puppeteer.launch({ headless: true, ignoreHTTPSErrors: true });

  console.log('Taking screenshots...');

  for (let i = 0; i < devices.length; i++) {

    process.stdout.write(`${parseInt(((i / devices.length) * 100))}%\r`);

    const page = await browser.newPage();

    const pendingXHR = new PendingXHR(page);

    await page.goto(url, { waitUntil: 'networkidle2' });

    await pendingXHR.waitForAllXhrFinished();

    if (withStorage) {
      for (let inc = 0; inc < localStorageData.length; inc++) {
        const name = localStorageData[inc].name;
        const data = localStorageData[inc].data;
        await page.evaluate(({name, data}) => {
github umpox / generateDeviceScreenshots / index.js View on Github external
const browser = await puppeteer.launch();
    let page = await browser.newPage();
    let currentDevice;

    try {
        if (selectedDevices !== "all") {
            for (let i=0; i
github eugeniosegala / snap-this / index.js View on Github external
const snapThis = async () => {

  console.log('Starting...');

  const browser = await puppeteer.launch({ headless: true, ignoreHTTPSErrors: true });

  console.log('Taking screenshots...');

  for (let i = 0; i < devices.length; i++) {

    process.stdout.write(`${parseInt(((i / devices.length) * 100))}%\r`);

    const page = await browser.newPage();

    const pendingXHR = new PendingXHR(page);

    await page.goto(url, { waitUntil: 'networkidle2' });

    await pendingXHR.waitForAllXhrFinished();

    if (withStorage) {
      for (let inc = 0; inc < localStorageData.length; inc++) {
        const name = localStorageData[inc].name;
        const data = localStorageData[inc].data;
        await page.evaluate(({name, data}) => {
          localStorage.setItem(name, data);
        }, {name, data});