w3c / webdriver-bidi

Bidirectional WebDriver protocol for browser automation
https://w3c.github.io/webdriver-bidi/
378 stars 42 forks source link

Support emulation of network conditions #776

Open whimboo opened 2 months ago

whimboo commented 2 months ago

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

  1. 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.

  2. 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).

  3. 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:

Benefits

Questions

References

juliandescottes commented 2 months ago

Are there any known limitations that might prevent isolating network conditions for individual browsing contexts?

If the question is on the implementation side, on Firefox we support Network Throttling in DevTools scoped by tab. So it shouldn't be an issue.

css-meeting-bot commented 1 month ago

The Browser Testing and Tools Working Group just discussed emulator - Support emulation of network conditions.

The full IRC log of that discussion <AutomatedTester> topic: emulator - Support emulation of network conditions
<AutomatedTester> github: https://github.com/w3c/webdriver-bidi/issues/776
<dmurph> q+ I have a question about testing / interception new navigables (github issue https://github.com/w3c/webdriver-bidi/issues/756), it's on the topic bank - would that be possible to quickly check in about?
<dmurph> q+ to ask about github issue: https://github.com/w3c/webdriver-bidi/issues/756
<jgraham> q?
css-meeting-bot commented 1 month ago

The Browser Testing and Tools Working Group just discussed Emulation - Support emulation of network conditions.

The full IRC log of that discussion <AutomatedTester> topic: Emulation - Support emulation of network conditions
<AutomatedTester> github: https://github.com/w3c/webdriver-bidi/issues/776
<jgraham> q+
<AutomatedTester> AutomatedTester: This is something that is regularly coming up to allow people to test their applications and make sure they are useable offline as well as making sure that service workers are installed properly and application is usable in "low" network areas
<AutomatedTester> ack jgraham
<AutomatedTester> jgraham: There are clear uses and I am in favour of working on this. I wonder if setOffline should be a separate command and isn't related to emulating the network
<AutomatedTester> ... and I don't think we should be using magic numbers here
<AutomatedTester> ... I also think the spec work here will be very intricate. we can't just use Fetch here
<AutomatedTester> q?
<sadym> q+
<AutomatedTester> ack sadym
<AutomatedTester> sadym: having offline and throughput will be good
<AutomatedTester> ... and I am in favour of dropping `-1` as a value