Skip to content

Commit

Permalink
Switch to puppeteer-core so that Chromium doesn't get downloaded unti…
Browse files Browse the repository at this point in the history
…l --dynamic is used the first time
  • Loading branch information
papandreou committed Jul 30, 2019
1 parent c85d79f commit e925ba9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
19 changes: 18 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ async function transferResults(jsHandle) {
return results;
}

async function downloadAndLaunchHeadlessBrowser() {
const puppeteer = require('puppeteer-core');
const browserFetcher = puppeteer.createBrowserFetcher();
const preferredRevision = puppeteer._launcher._preferredRevision;
const localRevisions = await browserFetcher.localRevisions();
let revisionInfo;
if (localRevisions.includes(preferredRevision)) {
revisionInfo = await browserFetcher.revisionInfo(preferredRevision);
} else {
console.log(`Downloading Chromium ${preferredRevision}`);
revisionInfo = await browserFetcher.download(preferredRevision);
}
return await puppeteer.launch({
executablePath: revisionInfo.executablePath
});
}

async function tracePageInBrowser(browser, assetGraph, htmlAsset) {
const page = await browser.newPage();
await page.setRequestInterception(true);
Expand Down Expand Up @@ -281,7 +298,7 @@ module.exports = async (argv, console) => {
let tracesByAsset;
if (dynamic) {
tracesByAsset = new Map();
const browser = await require('puppeteer').launch();
const browser = await downloadAndLaunchHeadlessBrowser();
try {
for (const htmlAsset of assetGraph.findAssets({
type: 'Html',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"lodash.groupby": "^4.6.0",
"postcss-values-parser": "^2.0.1",
"pretty-bytes": "^5.1.0",
"puppeteer-core": "^1.19.0",
"urltools": "^0.4.1",
"yargs": "^12.0.2"
},
Expand All @@ -66,7 +67,6 @@
"nyc": "^13.0.1",
"prettier": "~1.18.2",
"proxyquire": "^2.1.1",
"puppeteer": "^1.18.1",
"sinon": "^6.1.5",
"unexpected": "^10.39.1",
"unexpected-set": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--timeout 30000
--timeout 300000

0 comments on commit e925ba9

Please sign in to comment.