puppeteer模拟3G网络
- 分类:【工具使用】
- 浏览【126】
- 评论【0】
- 更新【2020-11-10 14:33:55】
puppeteer要模拟3G,4G网络需要利用DevTools Protocol。 Chrome DevTools Protocol
page = await browser.newPage();
// 模拟3g网络
let cdp = await page.target().createCDPSession();
await cdp.send('Network.emulateNetworkConditions', {
'offline': false,
'downloadThroughput': 600 * 1024,//(bytes/sec) 3G最高600K/s 4G 最高10M/s
'uploadThroughput': 600 * 1024,//(bytes/sec)
'latency': 0
});
await page.setCacheEnabled(false);
await page.goto(url);