Skip to content

Instantly share code, notes, and snippets.

@tai
Created May 6, 2019 10:05
Show Gist options
  • Save tai/01eabe1179582832bfb589738ceceaf2 to your computer and use it in GitHub Desktop.
Save tai/01eabe1179582832bfb589738ceceaf2 to your computer and use it in GitHub Desktop.
#!/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