I want to install puppeteer with Glitch.com.
However, when I run npm i puppeteer
, it says that the Node version is not supported. (Node: v16.14.2, npm: v7.20.6)
So I tried to install Puppeteer version 19.6.1. However, this version is deprecated and will not install.
Is there a way to install Puppeteer without changing the Node version?
At the current moment, Glitch only seems to support Node up to 16.x by default. There may be ways to circumvent it, but I haven't tried anything yet.
Working with the current system, if you're OK with a slightly older Puppeteer version, the following works for me. It's running at https://hello-puppeteer.glitch.me and https://glitch.com/~hello-puppeteer.
package.json:
{
"name": "hello-puppeteer",
"version": "0.1.0",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.19.2",
"puppeteer": "^17.1.3"
},
"engines": {
"node": "16.x"
}
}
server.js:
const express = require("express");
const puppeteer = require("puppeteer");
const app = express();
app.get("/", async (request, response) => {
let browser;
try {
browser = await puppeteer.launch({args: ["--no-sandbox"]});
const [page] = await browser.pages();
const url = request.query.url ?? "https://pptr.dev";
await page.goto(url, {waitUntil: "domcontentloaded"});
response.send(await page.title());
}
catch (err) {
response.send(err.message);
}
finally {
await browser?.close();
}
});
const listener = app.listen(process.env.PORT, () => {
console.log(`Your app is listening on port ${listener.address().port}`);
});
See also https://glitch.com/~jest-puppeteer for a Jest/Puppeteer setup.
For future visitors, if these projects or the information in this post becomes outdated, drop a comment and I'll upgrade. This thread can be used to track Glitch's progress on Node 18+ support.