0

According to this Vercel page it seems like using a Vercel function to run Puppeteer should be doable, but not matter what I do, I end up with Unhandled Rejection: Error: Unable to get browser page. How can I achieve this successfully?

Here's my current setup:

let customPuppeteer = {};
        let customExecutablePath = {};

        const isVercel = !!process.env.VERCEL;
        if (isVercel) {
          const puppeteer = await import("puppeteer-core");
          const chromium = (await import("@sparticuz/chromium")).default;
          const executablePath = await chromium.executablePath();
          customPuppeteer = {
            puppeteer: puppeteer,
          };

          customExecutablePath = {
            args: [
              ...new Set([...chromium.args, "--no-sandbox", "--disable-gpu"]),
            ],
            executablePath,
          };
        }

        const imageBuffer = (await nodeHtmlToImage({
          html: sizedHtml,
          type: "png",
          quality: 100,
          ...customPuppeteer,
          puppeteerArgs: {
            defaultViewport: {
              width: size.width,
              height: size.height,
            },
            timeout: 60000,
            ...customExecutablePath,
          },
        })) as Buffer;

I sometimes get other errors related to failure to launch Chrome altogether, or failure to reboot Chrome. But never once has this run successfully. (It works as expected in dev).

1
  • There is not a lot to go on here. Have you confirmed that the Chrome binary is available in Vercel? Commented Aug 23 at 11:09

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.