Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Dec 27, 2022 · 6 comments

Comments

@mflisikowski
Copy link

mflisikowski commented Dec 27, 2022

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',
    },
  });
});
@mflisikowski
Copy link
Author

mflisikowski commented Dec 27, 2022

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/[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' },
    });
});

@marcomow
Copy link

marcomow commented Dec 30, 2022

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
Copy link

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

@mflisikowski
Copy link
Author

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
Copy link

marcomow commented Jan 4, 2023

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants