Repository navigation
Trying to use puppeteer in vercel deployment #63961
Replies: 8 comments 3 replies
|
I tried this last year and it worked https://github.com/nicnocquee/instagram-puppet/tree/main but need to use the specific version of the chrome-aws-lambda and puppeteer-core |
|
Hey, did you find any solution? |
|
any solution? |
|
any solution ? |
|
This is a recurring issue — Puppeteer works locally because you have Chrome installed, but Vercel's serverless environment doesn't include it. The If you're primarily generating PDFs rather than doing browser automation, there are alternatives that skip Chromium entirely:
You send HTML, get a PDF back — no Chromium binary needed in your Vercel function: import { PDF } from "presa-sdk";
const { buffer } = await PDF.generate({ html, format: "A4" });Deploys to Vercel without issues since it's just an HTTP call. |
|
When deploying Next.js with Puppeteer on Vercel, the issue usually happens because Vercel serverless functions do not include a full Chromium environment. A common solution is to use Steps you can try:
Example: import chromium from "chrome-aws-lambda";
import puppeteer from "puppeteer-core";
export default async function handler(req, res) {
const browser = await puppeteer.launch({
args: chromium.args,
executablePath: await chromium.executablePath,
headless: chromium.headless
});
const page = await browser.newPage();
await page.goto("https://example.com");
const title = await page.title();
await browser.close();
res.status(200).json({ title });
} |
|
There's a guide here: |
|
This error happens because Vercel Serverless Functions execute inside lightweight container environments with strict uncompressed size limits (50MB–250MB) and stripped system libraries (no ALSA, NSS, or Mesa graphics drivers needed by Chromium). While If your core goal in Next.js is document generation (creating PDF invoices, tickets, contracts, or reports) rather than scraping external websites:
export async function POST(req: Request) {
const data = await req.json();
const res = await fetch("https://your-doc-engine.internal/compile", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
const pdfBuffer = await res.arrayBuffer();
return new Response(pdfBuffer, {
headers: { "Content-Type": "application/pdf" },
});
}This keeps your Next.js deployments lightweight, deterministic, and free of browser layer crashes. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Summary
I am trying to use puppeteer to launch a chrome browser in next js api , but this is not working when I deploy to Vercel. This is working in my local machine which is a mac using Apple M1 and macos monterey.
The vercel node version is 20
The code can be found in this repo https://github.com/abhishekmg/screenshot-test
The screenshot logic is in src/api/route.js
Iam getting this error when I push to vercel
I tried using
chrome-aws-lamdaas mentioned https://github.com/orgs/vercel/discussions/124, but still facing issuesExample
https://github.com/abhishekmg/screenshot-test
All reactions