Created
May 6, 2019 10:05
-
-
Save tai/01eabe1179582832bfb589738ceceaf2 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
#!/usr/bin/env node | |
const PPT = require('puppeteer'); | |
const PDD = require('puppeteer/DeviceDescriptors'); | |
const PuppeteerHar = require('puppeteer-har'); | |
(async () => { | |
const ua = await PPT.launch({ | |
headless: true, | |
args: ['--no-sandbox', '--disable-gpu'], | |
}); | |
const page = await ua.newPage(); | |
// inject delay | |
await page.setRequestInterception(true); | |
page.on('request', request => { | |
console.log(request.url()); | |
if (request.resourceType() === 'image') { | |
//request.abort(); | |
setTimeout(() => request.continue(), 9000); | |
//request.continue(); | |
} | |
else { | |
request.continue(); | |
} | |
}); | |
const har = new PuppeteerHar(page); | |
await har.start({ path: 'results.har' }); | |
await page.emulate(PDD['iPhone 6']) | |
await page.goto('https://www.yahoo.co.jp/', { | |
waitUntil: 'networkidle2', | |
timeout: 0, | |
}); | |
await page.screenshot({ path: 'out.png' }); | |
console.log(await page.title()) | |
await har.stop(); | |
await ua.close(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment