Skip to content

Instantly share code, notes, and snippets.

@martinschierle
Created October 15, 2019 10:29
Show Gist options
  • Save martinschierle/5a0af5630b76be00dff7e357720795f3 to your computer and use it in GitHub Desktop.
Save martinschierle/5a0af5630b76be00dff7e357720795f3 to your computer and use it in GitHub Desktop.
const puppeteer = require('puppeteer');
const devices = require('puppeteer/DeviceDescriptors');
const Good3G = {
'offline': false,
'downloadThroughput': 1.5 * 1024 * 1024 / 8,
'uploadThroughput': 750 * 1024 / 8,
'latency': 40
};
const phone = devices['Nexus 5X'];
async function run(url) {
// I can't get the experimental flag working on chromium, so let's start system chrome
const browser = await puppeteer.launch({headless: true});
let page = await browser.newPage();
const client = await page.target().createCDPSession();
await client.send('Network.enable');
await client.send('Network.emulateNetworkConditions', Good3G);
await client.send('Emulation.setCPUThrottlingRate', { rate: 20 });
await page.emulate(phone);
await client.send('Log.enable');
await client.send('Log.startViolationsReport', {config:[{name: "longTask", threshold: 0.005}]});
client.on('Log.entryAdded', async (entry) => {
//if(entry.entry.source!=="javascript") return;
console.log(JSON.stringify(entry.entry, null, 2));
});
// load page
await page.goto(url, {"timeout": "120000"});
await page.close();
await browser.close();
}
run("https://www.spiegel.de");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment