2022-10-06 15:30:00 +00:00
|
|
|
---
|
|
|
|
sidebar_label: PredefinedNetworkConditions
|
|
|
|
---
|
|
|
|
|
|
|
|
# PredefinedNetworkConditions variable
|
|
|
|
|
2024-06-07 09:34:25 +00:00
|
|
|
A list of pre-defined network conditions to be used with [Page.emulateNetworkConditions()](./puppeteer.page.emulatenetworkconditions.md).
|
2022-10-06 15:30:00 +00:00
|
|
|
|
2022-10-24 07:07:05 +00:00
|
|
|
#### Signature:
|
2022-10-06 15:30:00 +00:00
|
|
|
|
|
|
|
```typescript
|
|
|
|
PredefinedNetworkConditions: Readonly<{
|
|
|
|
'Slow 3G': NetworkConditions;
|
|
|
|
'Fast 3G': NetworkConditions;
|
2024-06-07 09:34:25 +00:00
|
|
|
'Slow 4G': NetworkConditions;
|
|
|
|
'Fast 4G': NetworkConditions;
|
2022-10-06 15:30:00 +00:00
|
|
|
}>;
|
|
|
|
```
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
```ts
|
|
|
|
import {PredefinedNetworkConditions} from 'puppeteer';
|
|
|
|
(async () => {
|
|
|
|
const browser = await puppeteer.launch();
|
|
|
|
const page = await browser.newPage();
|
2024-06-07 09:34:25 +00:00
|
|
|
await page.emulateNetworkConditions(PredefinedNetworkConditions['Slow 3G']);
|
|
|
|
await page.goto('https://www.google.com');
|
|
|
|
await page.emulateNetworkConditions(PredefinedNetworkConditions['Fast 3G']);
|
|
|
|
await page.goto('https://www.google.com');
|
|
|
|
await page.emulateNetworkConditions(PredefinedNetworkConditions['Slow 4G']); // alias to Fast 3G.
|
|
|
|
await page.goto('https://www.google.com');
|
|
|
|
await page.emulateNetworkConditions(PredefinedNetworkConditions['Fast 4G']);
|
2022-10-06 15:30:00 +00:00
|
|
|
await page.goto('https://www.google.com');
|
|
|
|
// other actions...
|
|
|
|
await browser.close();
|
|
|
|
})();
|
|
|
|
```
|