Open QA1980 opened 11 months ago
I'm having the same problem.
Same here.
I'm facing the same issue
@piyush-kacha @muhzak I got around this by not using serverless-plugin-chrome at all. I don't think it's being maintained anymore. Not sure what you're doing, but I ended up using @sparticuz/chromium with puppeteer to create my PDF generator.
HI,
Can you share sample for this? sparticuz/chromium also not working
@piyush-kacha @muhzak I got around this by not using serverless-plugin-chrome at all. I don't think it's being maintained anymore. Not sure what you're doing, but I ended up using @sparticuz/chromium with puppeteer to create my PDF generator.
Here is a working example using node 18.
Ours runs as a serverless lambda function that we pass values to (ie. the url) and it will save the PDF to an S3 bucket. It includes caching the PDF and a bunch of other features including saving the file locally for testing.
I stripped out everything but the saving locally part to make it less confusing and easier to get running. Just make sure you have a temp directory where you run this, be sure to install the dependencies, and it should work.
//.env
IS_OFFLINE = true
require("dotenv").config();
const chromium = require("@sparticuz/chromium");
const fs = require("fs");
const path = require("path");
// If you're running this as a lambda function, use puppeteer-core
const puppeteer =
process.env.IS_OFFLINE === "true"
? require("puppeteer")
: require("puppeteer-core");
const pdfGenerator = async () => {
const url = "http://news.google.com";
const executablePath =
process.env.IS_OFFLINE === "true"
? undefined
: await chromium.executablePath();
chromium.setGraphiceMode = false;
const browser = await puppeteer.launch({
args: ["--font-render-hinting=none", ...chromium.args],
defaultViewport: chromium.defaultViewport,
executablePath: executablePath,
headless: chromium.headless,
ignoreHTTPSErrors: true,
});
const page = await browser.newPage();
await page.goto(url, { waitUntil: "load" });
const pdfBuffer = await page.pdf({
printBackground: true,
preferCSSPageSize: true,
margin: {
top: "0px",
right: "0px",
bottom: "0px",
left: "0px",
},
waitUntil: "networkidle0",
});
const filePath = path.join("./temp", "myFile.pdf");
fs.writeFileSync(filePath, pdfBuffer);
console.log("Stored locally at " + filePath);
process.exit();
};
pdfGenerator();
Environment: linux, node 20.9.0, framework 3.36.0 (local), plugin 7.1.0, SDK 4.4.0 Docs: docs.serverless.com Support: forum.serverless.com Bugs: github.com/serverless/serverless/issues
Error: Error: The "serverless-plugin-chrome" plugin only supports the Node.js 6.10 or 8.10 runtimes. Your service is using the "nodejs18.x" provider. at throwIfUnsupportedRuntime (/workspace/node_modules/serverless-plugin-chrome/dist/index.js:27:11) at new ServerlessChrome (/workspace/node_modules/serverless-plugin-chrome/dist/index.js:82:5) at PluginManager.addPlugin (/workspace/node_modules/serverless/lib/classes/plugin-manager.js:91:28) at /workspace/node_modules/serverless/lib/classes/plugin-manager.js:137:69 at Array.forEach ()
at PluginManager.loadAllPlugins (/workspace/node_modules/serverless/lib/classes/plugin-manager.js:137:44)
at async Serverless.init (/workspace/node_modules/serverless/lib/serverless.js:146:5)
at async /workspace/node_modules/serverless/scripts/serverless.js:601:7