Home > Mobile >  puppeteer.launch not loading
puppeteer.launch not loading

Time:05-05

I am trying to open a page using puppeteer headless. However, puppeteer.launch is taking extremely long and the process isn't able to finish. Code:

const puppeteer = require("puppeteer");
async function getVisual() {
  try {
    const URL =
      "https://www.bannerbear.com/blog/ways-to-speed-up-puppeteer-screenshots/";
    const browser = await puppeteer.launch((headless = true), {
      ignoreDefaultArgs: ["--disable-extensions"],
      timeout: 3000,
    });
    const page = await browser.newPage();
    console.log("hi");

    await page.goto(url);
    await page.screenshot({ path: "screenshot.png" });
    await page.pdf({ path: "page.pdf" });

    await browser.close();
  } catch (error) {
    console.error(error);
  }
}

getVisual();

CodePudding user response:

In your puppeteer.launch() statement, you need to put those parameters in a single object.

Remove the "(headless = true)", and put it as a new item in the object. Like puppeteer.launch({headless: true, ignoreDefaultArgs: [], timeout: 3000})...

The documentation states how to use parameters here.

  • Related