Puppeteer Chromium Resolver
Tool to resolve puppeteer and chromium faster, detect local installed chromium, download chromium with custom mirror host, cache chromium revision out of node_modules, test chromium headless being launchable.
- Tool to customize puppeteer
- Detect local chromium automatically
- Download chromium from custom mirror host
- Cache chromium to local folder
- Try launching chromium and resolve launchable and version
- Resolve chromium executablePath and puppeteer
Install
npm install puppeteer-chromium-resolver --save
Usage
[Async] dynamic detection and downloading chromium
(async () => {
const PCR = require("puppeteer-chromium-resolver");
const option = {
revision: "",
detectionPath: "",
folderName: ".chromium-browser-snapshots",
defaultHosts: ["https://storage.googleapis.com", "https://npm.taobao.org/mirrors"],
hosts: [],
cacheRevisions: 2,
retry: 3,
silent: false
};
const stats = await PCR(option);
const browser = await stats.puppeteer.launch({
headless: false,
args: ["--no-sandbox"],
executablePath: stats.executablePath
}).catch(function(error) {
console.log(error);
});
const page = await browser.newPage();
await page.goto("https://www.npmjs.com/package/puppeteer-chromium-resolver");
await browser.close();
})();
[Sync] chromium will be pre-downloaded when PCR installation, so calling getStats() will get PCR stats from previous installation.
const PCR = require("puppeteer-chromium-resolver");
const stats = PCR.getStats();
if (stats) {
stats.puppeteer.launch({
headless: false,
args: ["--no-sandbox"],
executablePath: stats.executablePath
}).then(function(browser){
}).catch(function(error) {
console.log(error);
});
}
Option from root package.json with "pcr" object
{
"name": "",
"version": "",
"dependencies": {},
"pcr": {
"revision": "869685"
}
}
Return Stats
Property | Type | |
---|
revision | String | current chromium revision |
executablePath | String | chromium executable path |
folderPath | String | chromium folder path |
local | Boolean | exists local chromium |
url | String | chromium download url |
launchable | Boolean | chromium launchable |
chromiumVersion | String | chromium version |
puppeteerVersion | String | puppeteer version |
puppeteer | Object | puppeteer module |
How to make puppeteer work with puppeteer-chromium-resolver
- 1, Stop the automatic download of Chromium with following settings in .npmrc
puppeteer_skip_download = true
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD = true
(one more setting for puppeteer v2.x)
- 2, Sets env PUPPETEER_EXECUTABLE_PATH to PCR executablePath globally or pass in launch option executablePath
(async () => {
const PCR = require("puppeteer-chromium-resolver");
const puppeteer = require("puppeteer");
const stats = await PCR();
process.env.PUPPETEER_EXECUTABLE_PATH = stats.executablePath;
const browser = await puppeteer.launch({
executablePath: stats.executablePath,
headless: false
});
})();
CHANGELOG
major version following puppeteer-core
-
v15.0.0
- updated puppeteer-core to ^15.0.0
-
v14.0.0
- updated puppeteer-core to ^14.0.0
-
v12.0.0
- updated puppeteer-core to ^12.0.1
-
v11.0.0
- updated puppeteer-core to ^11.0.0
-
v10.0.0
- updated puppeteer-core to ^10.0.0
-
v9.0.0
- updated puppeteer-core to ^9.1.1
-
v8.1.1
- supported reading option from root package.json with "pcr" object
- updated PCR(option) API to support using stats cache
-
v8.0.0
- updated puppeteer-core to v8.0.0
-
v7.0.0
- updated puppeteer-core to v7.1.0
-
v5.2.0
- updated puppeteer-core to v5.2.1
-
v5.0.1
- updated puppeteer-core to v5
- added sync API getStats()
-
v4.0.0
- updated puppeteer-core to v4
-
v3.2.0
- updated puppeteer-core to v3
-
v3.1.0
- updated puppeteer-core version to 2.1.1
- auto detect host response time and download from quicker one
-
v3.0.1
-
v2.0.2
- added option cacheRevisions to cache multiple revisions
-
v3.0.0
- updated puppeteer-core version to v2.0.0
-
v2.0.1
- updated puppeteer-core version to v1.19.0
- refactoring with async/await
- fixed requesting timeout
-
v1.0.12
- updated puppeteer-core version to v1.18.1
- fixed a gauge log issue