- Last Updated: [[2020-12-08]]
- [[Network bandwidth throttling]]
- Source: https://fdalvi.github.io/blog/2018-02-05-puppeteer-network-throttle/
- Uses [[Network throttling in Chrome DevTools]] - specifically, the `Network.emulateNetworkConditions` property - to restrict bps.
- Note: while [[Network bandwidth]] is typically measured in __bits per second__, this approach actually restricts __bytes__ per second.
- # Required attributes
- ```javascript
let config = {
// Whether chrome should simulate
// the absence of connectivity
'offline': false,
// Simulated download speed (bytes/s)
'downloadThroughput': 500,
// Simulated upload speed (bytes/s)
'uploadThroughput': 500,
// Simulated latency (ms)
'latency': 20
}```
- # Example
- ```javascript
const puppeteer = require('puppeteer')
puppeteer.launch().then(async browser => {
// Create a new tab
const page = await browser.newPage()
// Connect to Chrome DevTools
const client = await page.target().createCDPSession()
// Set throttling property
await client.send('Network.emulateNetworkConditions', {
'offline': false,
'downloadThroughput': 200 * 1024 / 8,
'uploadThroughput': 200 * 1024 / 8,
'latency': 20
})
// Navigate and take a screenshot
await page.goto('https://fdalvi.github.io')
await page.screenshot({path: 'screenshot.png'})
await browser.close()
})```
- Source: https://fdalvi.github.io/blog/2018-02-05-puppeteer-network-throttle/
- This simulates a 200 Kb/s connection with 20ms latency
- # Other values
- [[Network bandwidth in bps]]
-