lucacasonato / deno-puppeteer

A port of puppeteer running on Deno
https://deno.land/x/puppeteer
MIT License
453 stars 44 forks source link

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. #72

Open mflisikowski opened 1 year ago

mflisikowski commented 1 year ago

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/puppeteer@16.2.0/install.ts" to download a supported browser binary.

... 

🐉 >PUPPETEER_PRODUCT=chrome deno run -A --unstable https://deno.land/x/puppeteer@16.2.0/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/puppeteer@16.2.0/mod.ts';
import { serve } from 'https://deno.land/std@0.168.0/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',
    },
  });
});
mflisikowski commented 1 year ago

Temp solution browserless docs

  1. Cloud based browserless.io
    const browser = await puppeteer.connect({
       browserWSEndpoint: 'wss://chrome.browserless.io?token=<your_token>',
    });
  1. 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/puppeteer@16.2.0/mod.ts';
import { serve } from 'https://deno.land/std@0.168.0/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' },
    });
});
marcomow commented 1 year ago

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

marcomow commented 1 year ago

(btw @mflisikowski the page you try to scrape in the example is not accessible https://mflisikowski.dev/cv)

mflisikowski commented 1 year ago

yes, yes I know that this route does not exist (yet :)), locally generate pdf with 404, It is enough for me to test purpose :)

marcomow commented 1 year ago

Also, I've realised that actually the experimental javascript flag is not needed as the js in my target page is actually being executed 😅

mflisikowski commented 1 year ago

I found another solution I decided to leave the information here as well :) doppio.sh