import puppeteer from 'puppeteer';

export const screenShot = async (filename, time) => {
  const browser = await puppeteer.launch({
    headless: true,
    args: ["--no-sandbox"],
  });

  
  try {
    // Open a new page
    const page = await browser.newPage();
    await page.goto("https://logs.danielvu.com/screenShot/" + filename);
    const bodyHandle = await page.$("body");
    const { height } = await bodyHandle.boundingBox();
    await bodyHandle.dispose();
    await page.setViewport({ width: 1920, height: 800 });
    setTimeout(async () => {
      await page.screenshot({ path: "/home/screenshot/"+time+".png" });
      browser.close();
    }, 5000);
  } catch (error) {
    console.log(error);
  }
};
