Replies: 2 comments 3 replies
-
DeprecatedThe following response contains deprecated dependencies. Furthermore, the code is not compatible with current versions of Please refer to the following (updated) repository https://github.com/StefanZoneExamples/deta-puppeteer. Yes it is possible, although the solution is a bit strange. The solution is to use StepsFirst install the required packages. I'm assuming you are using
Next, in your
const express = require("express");
const chromium = require('chrome-aws-lambda');
const app = express();
app.get("/screenshot", async (request, response) => {
const executablePath = await chromium.executablePath;
const browser = await chromium.puppeteer.launch({
args: chromium.args,
executablePath: executablePath,
headless: chromium.headless,
});
try {
const page = await browser.newPage();
await page.goto("https://example.com");
const screenshot = await page.screenshot({ fullPage: true });
// IMPORTANT: https://docs.deta.sh/docs/common_issues/#nodejs-micros-cannot-serve-binary-files
response.type("png");
response.send(screenshot);
} catch (error) {
res.send("An error occured.");
} finally {
await browser.close();
}
});
const port = 3000;
if (!process.env.DETA_RUNTIME) {
app.listen(port, () => console.log("Started on http://localhost:3000"));
}
module.exports = app; Finally, it is VERY important to note that Deta Micros cannot handle binary files. I spent some time banging my head on the table trying to solve this problem. But it is easily solvable. First create a
Then, run the following command with the Deta CLI. deta update -e .env And then it should work. If not, feel free to contact me. I'm running Puppeteer successfully on a Deta Micro. 😃 |
Beta Was this translation helpful? Give feedback.
-
Hey there, specifying the port To troubleshoot, please try calling your endpoint with the |
Beta Was this translation helpful? Give feedback.
-
Hello, i want to ask about Deta Micros.
Can i install Puppeteer in deta micros? Because, when i try to install that package and deta deploy that error for unknow reason.
Beta Was this translation helpful? Give feedback.
All reactions