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).