Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

2K
Vistas
Could not find expected browser chrome locally

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"
},
10 months ago · Santiago Trujillo
6 Respuestas
Responde la pregunta

0

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,
    });
10 months ago · Santiago Trujillo Denunciar

0

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

cd ./node_modules/puppeteer
npm run install

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

10 months ago · Santiago Trujillo Denunciar

0

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.

10 months ago · Santiago Trujillo Denunciar

0

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.

10 months ago · Santiago Trujillo Denunciar

0

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()

10 months ago · Santiago Trujillo Denunciar

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' });
10 months ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.