Puppeteer:为不同平台下载 Chromium [英] Puppeteer: Download Chromium for different platforms

查看:21
本文介绍了Puppeteer:为不同平台下载 Chromium的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Puppeteer 构建一个 UI 自动化程序,并将它作为一个 Electron 打包的应用程序发布.除了这个问题,它运行良好且流畅:

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 未下载当应用在与应用打包平台不同的平台上执行时抛出异常.

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.

说得好一点,我正在 Linux 环境中开发,我正在为 Linux 和 Windows 打包我的应用程序,Linux 应用程序可以正常工作,而 Windows 应用程序不能.

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.

问题是:Chromium 是在 npm install 时间下载的,而且是根据当前平台选择性完成的.作为当前的 Linux 平台,这个 Chromium 版本不管发布在每个平台的应用程序上.

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. 在 npm install 时下载全平台 Chromium(在开发机器上)
  2. 在打包时有选择地下载 Chromium(仍在开发机器上)
  3. 强制我的用户在运行时下载 Chromium(例如在第一次使用时)

问题是我没有找到任何可用于此目的的 Puppeteer 配置.

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

谢谢

推荐答案

更新@Pasi 的答案,以下适用于 "puppeteer": "^1.15.0"

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

这篇关于Puppeteer:为不同平台下载 Chromium的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆