deno-puppeteer
deno-puppeteer copied to clipboard
Error: Could not find browser revision XXX. Run "PUPPETEER_PRODUCT=chrome deno run -A --unstable https://deno.land/x/puppeteer@VERSION/install.ts" to download a supported browser binary.
Hi, I'm stuck looking for a browser version on my Apple M1 Pro, when I added the puppeteer package, I can't run Supabase function successfully anymore.
Deno info:
🐉 >deno info
DENO_DIR location: /Users/mateuszflisikowski/Library/Caches/deno
Remote modules cache: /Users/mateuszflisikowski/Library/Caches/deno/deps
npm modules cache: /Users/mateuszflisikowski/Library/Caches/deno/npm
Emitted modules cache: /Users/mateuszflisikowski/Library/Caches/deno/gen
Language server registries cache: /Users/mateuszflisikowski/Library/Caches/deno/registries
Origin storage: /Users/mateuszflisikowski/Library/Caches/deno/location_data
Error after call http://localhost:54321/functions/v1/:
Error: Could not find browser revision 1022525. Run "PUPPETEER_PRODUCT=chrome deno run -A --unstable https://deno.land/x/[email protected]/install.ts" to download a supported browser binary.
...
🐉 >PUPPETEER_PRODUCT=chrome deno run -A --unstable https://deno.land/x/[email protected]/install.ts
Already downloaded at /Users/mateuszflisikowski/Library/Caches/deno/deno_puppeteer/chromium/mac-1022525/chrome-mac/Chromium.app/Contents/MacOS/Chromium
...
mateuszflisikowski ::: ~/Library/Caches/deno/deno_puppeteer/chromium
🌐 >ls -l
total 0
drwxr-xr-x 3 mateuszflisikowski staff 96 26 gru 21:02 mac-1022525
Supabase function code, that try to run.
import puppeteer from 'https://deno.land/x/[email protected]/mod.ts';
import { serve } from 'https://deno.land/[email protected]/http/server.ts';
serve(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://mflisikowski.dev/cv', {
waitUntil: 'networkidle2',
});
const pdf = await page.pdf({ format: 'A4' });
await browser.close();
return new Response(pdf, {
headers: {
'Content-Disposition': `attachment; filename="cv.pdf"`,
'Content-Type': 'application/pdf',
},
});
});
Temp solution browserless docs
- Cloud based browserless.io
const browser = await puppeteer.connect({
browserWSEndpoint: 'wss://chrome.browserless.io?token=<your_token>',
});
- Self-hosted browserless, deployed on railway.app, check: railway browserless template
const browser = await puppeteer.connect({
browserWSEndpoint: 'wss://browserless-production-XXXX.up.railway.app',
});
But... pdf generation is fails, only screenshot do the job correctly.
import puppeteer from 'https://deno.land/x/[email protected]/mod.ts';
import { serve } from 'https://deno.land/[email protected]/http/server.ts';
serve(async () => {
const browser = await puppeteer.connect({
browserWSEndpoint: 'wss://browserless-production-XXXX.up.railway.app',
// or
browserWSEndpoint: 'wss://chrome.browserless.io?token=<your_token>',
});
const page = await browser.newPage();
await page.goto('https://mflisikowski.dev/cv', {
waitUntil: 'networkidle2',
});
const screenshot = await page.screenshot();
await browser.close();
return new Response(screenshot, {
headers: { 'Content-Type': 'image/png' },
});
});
I'm having the same issue.
Even though I'm able to use puppeteer thanks to the browserless.io solution (thanks @mflisikowski!), still my puppeteer is not behaving as expected. I believe because it's not possible to run JS in browserless, and we should pass an extra arg, like:
await puppeteer.launch({
args: [
'--enable-features=ExperimentalJavaScript'
]
})
but it looks like it's not supported - see docs
(btw @mflisikowski the page you try to scrape in the example is not accessible https://mflisikowski.dev/cv)
yes, yes I know that this route does not exist (yet :)), locally generate pdf with 404, It is enough for me to test purpose :)
Also, I've realised that actually the experimental javascript flag is not needed as the js in my target page is actually being executed 😅
I found another solution I decided to leave the information here as well :) doppio.sh