Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppeteer: Download Chromium for different platforms

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

like image 953
balanza Avatar asked Dec 11 '17 16:12

balanza


1 Answers

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) })
like image 74
Pasi Avatar answered Sep 28 '22 06:09

Pasi