Heartsuit's Simple Blog

A place to hold mainly reading notes, and some technical stuff occasionally. 这里主要是一些读书笔记、感悟;还有部分技术相关的内容。


Project maintained by heartsuit Hosted on GitHub Pages — Theme by mattgraham

Chromium revision is not downloaded :Puppeteer根据不同的操作系统下载对应的Chromium

目录[-]

Problem: Chromium revision is not downloaded

  "scripts": {
    "start": "electron .",
    "packager": "electron-packager ./ awesome-app --platform=win32 --arch=all --out ./Executable --electronVersion 2.0.7 --overwrite --icon=./icon.ico"
  },

使用Electron在Windows64平台上打包为win64、ia32的应用,这在通常情况下应该都没问题;不过在这次的应用中使用了Puppeteer,打包后ia32应用在Windows32位系统上无法启动chrome,查看日志发现报错:Error: Chromium revision is not downloaded

Analysis

Puppeteer是在执行npm install过程中下载的,对应的路径为:\node_modules\puppeteer\.local-chromium

.local-chromium下有win64-579032\chrome-win32,启动其中的chrome.exe,查看版本信息:

Chromium
70.0.3508.0(开发者内部版本) (64 位)

也就是说,打包后不论什么系统、平台,puppeteer启动的始终都是win64的这个Chromium(即在哪个平台上打包,默认只会有相应平台的Chromium),显然,问题来了,在32位的Windows系统上,是无法启动64位的Chromium的。

那么,如何同时下载多个平台或者指定平台的Chromium呢?

文件\node_modules\puppeteer\install.js将告诉我们答案。

Solution

let platform = 'win32'; // mac, linux, win32 or win64
const BrowserFetcher = require('puppeteer/lib/BrowserFetcher');
let browserFetcher = new BrowserFetcher({ platform: platform });
const revision = require('puppeteer/package').puppeteer.chromium_revision;
const revisionInfo = browserFetcher.revisionInfo(revision);

console.log(revision)
console.log(revisionInfo)

browserFetcher.download(revisionInfo.revision)
  .then(() => { console.log('Done!') })
  .catch(err => { console.log('Error', err) })
  "scripts": {
    "start": "electron .",
    "puppeteer": "node puppeteer",
    "packager": "electron-packager ./ awesome-app --platform=win32 --arch=all --out ./Executable --electronVersion 2.0.7 --overwrite --icon=./icon.ico"
  },

Note

npm config set puppeteer_download_host https://storage.googleapis.com.cnpmjs.org

Reference


If you have any questions or any bugs are found, please feel free to contact me.

Your comments and suggestions are welcome!


「说点什么吧😊~~😊」: