Description
Currently, network condition emulation applies globally to the browser (if possible at all), but it would be very useful to emulate network disconnection or throttling for specific browsing contexts (such as tabs or windows) independently.
This feature would provide more control over testing scenarios where individual contexts simulate network loss or restricted connectivity, while other contexts remain unaffected.
Use Cases
-
Simulating Network Outages for Specific Tabs: Being able to emulate a network outage for a single tab or window while keeping other tabs connected. This is useful for testing progressive web apps (PWAs), handling network errors in single-page applications, or multi-tab synchronization.
-
Multi-Context Testing: Testing how different contexts react to network issues independently. This is especially useful in applications where different parts of the app rely on separate network calls (e.g., one window working while another goes offline).
-
Offline-First Applications: Testing apps that are designed to work offline in a more realistic scenario where only certain windows/tabs experience network issues, rather than the entire browser being set to offline mode.
Proposal
Introduce an API to WebDriver BiDi that allows specifying custom network conditions (e.g., offline, latency, download/upload throttling) for specific browsing contexts, rather than affecting the entire browser.
The API could look like:
- Command to set network offline for a specific context:
{ "method": "network.setNetworkConditions", "params": { "contexts": [ids], // The IDs of the browsing contexts or undefined for global settings "offline": true, // Set network to offline "latency": 0, // Optionally set latency "downloadThroughput": -1, // Optional: Disable downloads "uploadThroughput": -1 // Optional: Disable uploads } }
Benefits
- Granular Control: This feature allows testing different network conditions in a more targeted way, improving the ability to simulate real-world scenarios for developers building resilient, network-dependent applications.
- Better Testing for PWAs: Many progressive web apps require granular control over network state to properly test offline functionality.
- Non-disruptive Testing: Since this feature would apply to specific browsing contexts, it allows for more controlled testing without affecting the entire browser or other ongoing operations.
Questions
- Are there any known limitations that might prevent isolating network conditions for individual browsing contexts?