Created
June 25, 2018 08:38
-
-
Save pokutuna/6686e32b836ece1d5ce34e468d0cb1f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"puppeteer": "^1.5.0", | |
"speedline": "^1.3.3" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const puppeteer = require('puppeteer'); | |
const devices = require('puppeteer/DeviceDescriptors'); | |
const speedline = require('speedline'); | |
/** | |
* Usage | |
* $ node index.js [URL] [withCache] [isMobile] | |
*/ | |
const pageUrl = process.argv[2]; | |
const withCache = process.argv[3] ? true : false; | |
const isMobile = process.argv[4] ? true : false; | |
(async (pageUrl, withCache, isMobile) => { | |
const browser = await puppeteer.launch({ ignoreHTTPSErrors: true }); | |
const page = await browser.newPage(); | |
if (!isMobile) { | |
// analytics 見て PC で多い解像度 | |
await page.setViewport({ | |
width: 1366, | |
height: 768 | |
}); | |
} else { | |
// iPhone 7 | |
await page.setViewport({ | |
width: 375, | |
height: 667, | |
deviceScaleFactor: 2, | |
isMobile: true, | |
hasTouch: true, | |
isLandscape: false | |
}); | |
} | |
if (withCache) { | |
await page.setCacheEnabled(true); | |
await page.goto(pageUrl); | |
} | |
await page.tracing.start({ | |
screenshots: true, | |
path: 'trace.json' | |
}); | |
await page.goto(pageUrl); | |
await page.tracing.stop(); | |
await browser.close(); | |
const results = await speedline('trace.json'); | |
const metrics = ['speedIndex', 'perceptualSpeedIndex', 'first', 'complete', 'duration']; | |
console.log(metrics.join('\t')); | |
console.log(metrics.map((m) => results[m]).join('\t')); | |
})(pageUrl, withCache, isMobile); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment