Puppeteer: Download Chromium for different platforms
Asked Answered
E

3

9

I'm building a UI-automator with Puppeteer and I'm shipping it as a Electron-packaged app. It works nice-and-smooth except for this issue:

Chromium is not downloaded exception is thrown when the app is executed on a platform different than the one the app has been packaged on.

Better said, I'm developing on a Linux environment and I'm packaging my app for both Linux and Windows, Linux app works fine, Windows app doesn't.

The problem is: Chromium is downloaded at npm install time, and it's done selectively based on the current platform. Being current platform Linux, this very version of Chromium is then shipped regardlessly on every platform's app.

I should be able to do one of the following:

  1. Download all-platform Chromium when npm install (on dev machine)
  2. Download Chromium selectively at packaging time (still on dev machine)
  3. Force my users to download Chromium at runtime (at first usage for example)

The problem is I haven't found any Puppeteer configuration I can use for such purpose.

Thanks

Eavesdrop answered 11/12, 2017 at 16:59 Comment(3)
Chromium is present inside puppeteer in the file ".local-chromium" at least on Windows. So when you install all package including Puppeteer (npm install puppeteer) browser should be there. Hope this help you ;)Ipswich
Hi, thanks for commenting. What you said is correct as Chromium is been downloaded when you install puppeteer via npm. However, only the Chromium version corresponding to your current platform would be downloaded. Hence, if you build the application from a Linux environment to a WIndows environment, it won't find Chromium (as Chromium for windows hasn't been installed). Unfortunately, that's actually the case when you package your app with ElectronEavesdrop
@Eavesdrop Did you find any solution for the problem?Arp
F
3

The Chromium download is done by node_modules/puppeteer/install.js during npm install. You could call this code from your application's build scripts. For example:

const Downloader = require('puppeteer/lib/Downloader');
const revision = require('puppeteer/package').puppeteer.chromium_revision;

Downloader.createDefault().downloadRevision('win64', revision, () => undefined)
  .then(() => { console.log('Done!') })
  .catch(err => { console.log('Error', err) })
Fosterling answered 13/12, 2017 at 7:56 Comment(2)
I believe this solution is outdated, as ChromiumDownloader doesn't seem to exist anymore anywhere in the puppeteer project.Calore
Thanks for pointing this out - I updated the code to work with Puppeteer 1.0.0.Fosterling
W
3

An update to @Pasi's answer, the following works for "puppeteer": "^1.15.0"

const puppeteer = require('puppeteer');
const browserFetcher = puppeteer.createBrowserFetcher({ platform: 'win64' });
const revision = require('puppeteer/package').puppeteer.chromium_revision;

browserFetcher.download(revision)
  .then(() => console.log('Done'))
  .catch(error => console.log('Error', error))
Wanton answered 28/4, 2019 at 14:20 Comment(2)
I am working with electron-puppeteer and I want to download chromium when I install app on windows, mac and linux. How can I do it any idea????Cobwebby
Did you find a solution @baj9032?Arp
C
1

Update for 2023:

After hours of searching I found a method to do it today. Might be helpful for anyone else struggling.

const puppeteer = require("@puppeteer/browsers");

(async() => {
    const buildId = '114.0.5735.133' //which version you want to download

    await puppeteer.install({
        cacheDir: "/Users/full/path/here/win32",
        browser: 'chrome',
        platform: 'win32', //or linux, mac, mac_arm, win64
        buildId
    });
    
    console.log("done");
})();
Convector answered 13/7, 2023 at 8:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.