'use strict';

const puppeteer = require('puppeteer');

const createPdf = async() => {
  let browser;
  try {
    browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']});
    const page = await browser.newPage();
    //await page.setViewport({width: 794, height: 1122, deviceScaleFactor: 1});
    await page.goto(process.argv[2], {timeout: 3000, waitUntil: 'networkidle2'});
    await page.waitFor(250);
    await page.emulateMedia('screen');
    await page._emulationManager._client.send(
      'Emulation.setDefaultBackgroundColorOverride',
      { color: { r: 0, g: 0, b: 0, a: 0 } }
    );
    
    console.log("AAAAAAAAAA");
    console.log("AAAAAAAAAA");
    
    console.log(process.argv[4]);
    console.log(process.argv[5]);
    await page.setViewport({
    
      width: parseFloat(process.argv[4]),
      height: parseFloat(process.argv[5]),
    });
    
    await page.screenshot({path: process.argv[3]});
    
    
  } catch (err) {
      console.log(err.message);
  } finally {
    if (browser) {
      browser.close();
    }
    process.exit();
  }
};
createPdf();