Skip to content

Commit

Permalink
feat: make it possible to run install.js script with `puppeteer-cor…
Browse files Browse the repository at this point in the history
…e` (#5325)

Co-authored-by: Mathias Bynens <mathias@qiwi.be>
  • Loading branch information
gziolo and mathiasbynens committed Jan 28, 2020
1 parent c283fea commit 0d243b7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/api.md
Expand Up @@ -371,6 +371,7 @@ In most cases, you'll be fine using the `puppeteer` package.
However, you should use `puppeteer-core` if:
- you're building another end-user product or library atop of DevTools protocol. For example, one might build a PDF generator using `puppeteer-core` and write a custom `install.js` script that downloads [`headless_shell`](https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md) instead of Chromium to save disk space.
- you're bundling Puppeteer to use in Chrome Extension / browser with the DevTools protocol where downloading an additional Chromium binary is unnecessary.
- you're building a set of tools where `puppeteer-core` is one of the ingredients and you want to postpone `install.js` script execution until Chromium is about to be used.

When using `puppeteer-core`, remember to change the *include* line:

Expand Down
12 changes: 8 additions & 4 deletions install.js
Expand Up @@ -14,10 +14,14 @@
* limitations under the License.
*/

// puppeteer-core should not install anything.
if (require('./package.json').name === 'puppeteer-core')
return;

/**
* This file is part of public API.
*
* By default, the `puppeteer` package runs this script during the installation
* process unless one of the env flags is provided.
* `puppeteer-core` package doesn't include this step at all. However, it's
* still possible to install Chromium using this script when necessary.
*/
if (process.env.PUPPETEER_SKIP_CHROMIUM_DOWNLOAD) {
logPolitely('**INFO** Skipping Chromium download. "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" environment variable was found.');
return;
Expand Down
1 change: 1 addition & 0 deletions utils/prepare_puppeteer_core.js
Expand Up @@ -22,4 +22,5 @@ const packagePath = path.join(__dirname, '..', 'package.json');
const json = require(packagePath);

json.name = 'puppeteer-core';
delete json.scripts.install;
fs.writeFileSync(packagePath, JSON.stringify(json, null, ' '));

0 comments on commit 0d243b7

Please sign in to comment.