Could not find expected browser chrome locally
Asked Answered
M

15

47

This Meteor code uses "puppeteer 8.0.0", "puppeteer-core 10.0.0", puppeteer-extra 3.1.18" and "puppeteer-extra-plugin-stealth 2.7.8", It gives this error:

Error: Could not find expected browser (chrome) locally. Run npm install to download the correct Chromium revision (884014).

Tried "npm install" for no avail. Reading up online, tried removing "puppeteer-core": "^10.0.0" from package.json dependencies for no avail.

Any help is much appriciated. Thanks

const puppeteer = require('puppeteer-extra');
const nameH = require('./NameH');

const puppeteerOptions = {
    headless: true,
    ignoreHTTPSErrors: true,
    args: ['--no-sandbox', '--single-process', '--no-zygote', '--disable-setuid-sandbox']
}

let browser;
let pageNameH;

const init = async () => {
    const StealthPlugin = require('puppeteer-extra-plugin-stealth');
    console.log('1')         //>>>>>>>>>>>> Prints 1
    puppeteer.use(StealthPlugin());
    console.log('2')         //>>>>>>>>>>>> Prints 2
    
    browser = await puppeteer.launch(puppeteerOptions);
    console.log('3') //>>>>>>>>> DID NOT PRINT <<<<<<<<<<<<<<<
    pageNameH = await browser.newPage();
    console.log('4')

    await pageNameH.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36');
    await pageNameH.setViewport({ width: 1366, height: 768 });
    await pageNameH.setRequestInterception(true);
    blockResources(pageNameH);
}

const blockResources = page => {
    page.on('request', (req) => {
    if (req.resourceType() == 'stylesheet' || req.resourceType() == 'font' || req.resourceType() == 'image') {
        req.abort();
    }
    else {
        req.continue();
    }
    });
}


export const abc = async (nm, loc) => {
    try {
    console.log('name try')       //>>>>>>>>>>>> Prints "name try"
    if (!(browser && pageNameH))
        await init();
    //use "required" nameh here

    } catch (error) { // print the error <<<<<<<<<<<<<<<<<<<<<<<<<
    console.log("Could not launch Puppeteer or open a new page.\n" + error);
    if (browser && browser.close === 'function') await browser.close();
    }
}


// included in package.json
"dependencies": {
    "@babel/runtime": "^7.11.2",
    "axios": "^0.21.1",
    "check": "^1.0.0",
    "cheerio": "^1.0.0-rc.6",
    "jquery": "^3.5.1",
    "meteor-node-stubs": "^1.0.1",
    "nightmare": "^3.0.2",
    "pending-xhr-puppeteer": "^2.3.3",
    "puppeteer": "^8.0.0",
    "puppeteer-core": "^10.0.0",
    "puppeteer-extra": "^3.1.18",
    "puppeteer-extra-plugin-adblocker": "^2.11.11",
    "puppeteer-extra-plugin-block-resources": "^2.2.9",
    "puppeteer-extra-plugin-stealth": "^2.7.8"
},
Merodach answered 20/6, 2021 at 0:10 Comment(6)
What happens if you try to delete node_modules folder and npm install again?Deme
The same problem even after deleting node_modules and npm install.Merodach
Could you also post your package.json? I mean just having a puppeteer in there should do it, so we'd better have a look at it.Deme
updated the post with pacakge.jsonMerodach
Had same problem, deleting node_modules and npm install worked for meStray
@davilj, I tried that for no avail,Merodach
C
109

may be you can try this, it works for me on linux(centOS), puppeteer(10.2.0).

cd ./node_modules/puppeteer
npm run install

If that fails, you can also try running:

cd ./node_modules/puppeteer
npm install

This will download the chromium to ./node_modules/puppeteer/.local-chromium

Community answered 11/8, 2021 at 2:12 Comment(6)
FYI, this also worked as a charm on AWS instance running CentOS, thanks a lotSentinel
[email protected]: It is npm run postinstall now. or yarn run postinstall what every you use.Elburr
Worked on Windows 10 as well.Xenophon
This works. why did that chromium thing disappear? It was working before.Meghanmeghann
Worked on MacOS Ventura, thanks a lot.Nanji
Worked perfectly on WSL2Aerography
A
22

Fixed it by running this command to install chromium manually.

node node_modules/puppeteer/install.js
Appeal answered 25/8, 2022 at 8:25 Comment(2)
I just had to run it, now it's a .mjs file instead of a .js, but it works all the same!Rant
in my case file named as install.mjs, but still error persistsLenoralenore
P
9

I had the same problem. I checked my env variables, and even though PUPPETEER_SKIP_CHROMIUM_DOWNLOAD was set to false, it was still not working. After I removed the variable (unset PUPPETEER_SKIP_CHROMIUM_DOWNLOAD for mac), it worked.

related dependancies:

  "dependencies": {
    "chrome-aws-lambda": "^10.0.0",
    "puppeteer-core": "^10.0.0",
  },
  "devDependencies": {
    "puppeteer": "^10.0.0",
  }

Launching Chromium:

    import chromium from "chrome-aws-lambda";

    const browser = await chromium.puppeteer.launch({
        executablePath: await chromium.executablePath,
    });
Popliteal answered 27/6, 2021 at 18:20 Comment(2)
Why is "puppeteer-core" a dependency even though you don't use it in the code? Specifically chromium.puppeteer.launch() instead of puppeteer.launch()Bullion
I tried these exact dependency versions and got but got WARNING: crash_report_exception_handler.cc(240)] UniversalExceptionRaise: (os/kern) failure (5)Bullion
W
6

if you are testing locally, make sure you have puppeteer installed as dev dependencies. specifically

npm install puppeteer --save-dev

https://github.com/alixaxel/chrome-aws-lambda/wiki/HOWTO:-Local-Development#workaround

this approach allows us to rely on puppeteer for local development and puppeteer-core for production deployments.

Worcester answered 19/7, 2021 at 6:8 Comment(1)
I copy pasted the npm install instruction in that README but got an error: Could not resolve dependency: npm ERR! peer puppeteer-core@"^10.1.0" from [email protected]Bullion
B
4

I had the same issue. What worked for me was to specify as the executablePath Puppeteer launch option the fullpath to the local chromium used by Puppeteer.

Something like this:

const launchOptions = {
  // other options (headless, args, etc)
  executablePath: '/home/jack/repos/my-repo/node_modules/puppeteer/.local-chromium/linux-901912/chrome-linux/chrome'
}

As noted in another answer, it seems that also referencing a chromium local binary would work, but I think it's a worse solution, since Puppeteer is guaranteed to work only with the local bundled version of Chromium.

Brendis answered 15/9, 2021 at 10:18 Comment(1)
This answer is so underrated. In my case, I don't want full puppeteer. Just puppeteer-core is ok, but it just couldn't find the browser on my ubuntu 18. I just needed to tell it where it is then it worked. Thank you.Lest
C
3

Throwing my answer in, in hopes that it helps someone not waste their entire evening like I did.

I was writing a Typescript server that used Puppeteer, and I'm using ESBuild to transpile from TS to JS. In the build step, esbuild was trying to bundle everything into one file, but I had to instruct it to preserve the Puppeteer import from node_modules.

I did this by marking puppeteer as external. See docs here.

Since npm i downloads a compatible version of chromium to the node_modules folder, once I preserved this import, it was able to find Chromium in the node_modules folder.

My build file looks like:

require("esbuild").buildSync({
  entryPoints: ["src/index.ts"],
  outdir: "build",
  bundle: true,
  platform: "node",
  target: "node16",
  external: ["puppeteer"],
});

And I run it with node prod-build.js.

Now in my code, I can just call launch!
const browser = await puppeteer.launch()

Castroprauxel answered 28/12, 2021 at 13:35 Comment(2)
Thanks for your answer. i'm testing rather a not popular setup - Angular Universal where Express serves both for REST API and for SSR. Adding the "puppeteer" to externals of a custom webpack config for server app solved the problem!Pestle
This approach pointed me in the right direction. There's another question (and answer) that highlights the exact steps when using angular univeral. This solved the issue for me, so I'm also linking it here: #70622851Methylnaphthalene
S
2

In my case, the issue was solved by installing a specific version of chrome. These were my error logs:

Error: Could not find Chrome (ver. 123.0.6312.122). This can occur if either
 1. you did not perform an installation before running the script (e.g. `npx puppeteer browsers install chrome`) or
 2. your cache path is incorrectly configured (which is: /root/.cache/puppeteer).

...

I solved the problem by installing the version from logs:

npx puppeteer browsers install [email protected]
Sassaby answered 18/4 at 9:7 Comment(0)
L
0

I used the installed version on my pc (maybe not what you're looking for)

const browser = await puppeteer.launch({headless:false,  executablePath: 
           'C:/Program Files/.../chrome.exe' });
Looksee answered 19/1, 2022 at 13:53 Comment(0)
P
0

You may need to install some dependencies depending on your OS. Check Puppeteer's Troubleshooting page for more details.

Padua answered 13/6, 2022 at 16:31 Comment(0)
S
0

I was having this error too and I noticed that I started getting such an error after updating my node from my Dockerfile to version ^16 (my puppeteer is in a container). How did I solve it? I downgraded my node from Dockerfile to version 12. Hope this resolves it...

OBS: I use Ubuntu 21.04 in machine.

EDIT ------

In newest versions of node, you need to go in ./node_modules/puppeteer and run command npm install, then the correct packages will be installed. I'm using that solution.

Scarce answered 23/6, 2022 at 14:29 Comment(0)
L
0

If you are using puppeteer in AWS SAM and you don't have puppeteer in dependencies, you can install the same in puppeteer-core using

   node node_modules/puppeteer/install.js

For this setup to work you will have to add chrome-aws-lambda in the devDependencies.

    "devDependencies": {
        "chrome-aws-lambda": "^10.1.0"
     }

Also before you take it to production don't forget to add the layer in your template.yaml file:

Layers:
     - !Sub 'arn:aws:lambda:ap-south-1:764866452798:layer:chrome-aws-lambda:25'
Laity answered 2/12, 2022 at 4:34 Comment(0)
C
0

For me the issue was that I ran npm install although I shouldn't have. Just deleted the node_modules folder and then ran again - now worked

Cantoris answered 9/3, 2023 at 20:29 Comment(0)
S
0

puppeteer-extra does not include chromium. (chromium is a headless version of chrome browser)

you need to install puppeteer package

npm install puppeteer

or just simple add executablePath if you don't want to install chromium (I assume you have Chrome browser in your system

const CHROME_EXECUTALBE_PATH = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
const browser = await puppeteer.launch({
            executablePath: CHROME_EXECUTALBE_PATH,
            headless: true
        });

to get the path, open your browse, type chrome://version/

Steno answered 8/9, 2023 at 0:26 Comment(0)
C
0

I'm using Volta and when I installed Puppeteer, I had accidentally used Node v10.16.0 with npm 6.9.0 and it apparently couldn't install Chromium.

Here's how I fixed it:

  1. volta pin [email protected]
  2. rm -rf node_modules
  3. npm install puppeteer

Now I can see Chromium in ~/.cache/puppeteer/ and I can run Puppeteer in my project.

Apparently, older Node versions interfere with the install script.

Congruency answered 11/11, 2023 at 8:58 Comment(0)
F
-1

Delete the node_modules folder and run

npm install
Folberth answered 9/6, 2023 at 10:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.