4

I was trying to build a quick lambda that prints a pdf with a specific url, but I get this error: Failed to launch chrome! spawn ...node_modules/puppeteer/.../chrome ... TROUBLESHOOTING

Methods mentioned here : https://github.com/GoogleChrome/puppeteer/issues/807#issuecomment-366529860 did not help me.

The code I'm using:

    const browser = await puppeteer.launch({
      headless: true,
      executablePath: '../../node_modules/puppeteer/.local-chromium/linux-624487/chrome-linux/chrome',
      args: ['--no-sandbox', '--disable-setuid-sandbox'],
    });
    try {
      const result = await exports.run(browser);
      callback(null, result);
    } catch (e) {
      callback(e);
    }

    ...
 
    exports.run = async (browser) => {
      // implement here
      // this is sample
      const page = await browser.newPage();
      await page.goto('https://www.google.com', {
        waitUntil: ['domcontentloaded', 'networkidle0']
      });
      console.log((await page.content()).slice(0, 500));

      await page.type('#lst-ib', 'aaaaa');
      // avoid to timeout waitForNavigation() after click()
      await Promise.all([
        // avoid to
        // 'Cannot find context with specified id undefined' for localStorage
        page.waitForNavigation(),
        page.click('[name=btnK]'),
      ]);

      // cookie and localStorage
      await page.setCookie({
        name: 'name',
        value: 'cookieValue'
      });
      console.log(await page.cookies());
      console.log(await page.evaluate(() => {
        localStorage.setItem('name', 'localStorageValue');
        return localStorage.getItem('name');
      }));
      const result = await page.pdf({
        path: 'hn.pdf',
        format: 'A4'
      });
      console.log(` typeof : ${typeof result}, pdf: ${result}`);
      await page.close();
      return 'done';
    };
1
  • actually puppeteer is trying to find chrome.exe but not able to find its problem with extraction of fodler Dec 24, 2020 at 5:56

1 Answer 1

4

check this path => \node_modules\puppeteer.local-chromium\win32-818858\chrome-win

you will notice chrome.exe will not exist, now got back one step => *\node_modules\puppeteer.local-chromium*

you will find zip file "chrome-win" extract it and move it int to => \node_modules\puppeteer.local-chromium\win32-818858

Now you may check it will work.

1
  • 1
    You sir, just saved me hours!!!! ❤️
    – 130nk3r5
    Jan 4, 2022 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.