Skip to content

Conversation

sadym-chromium
Copy link
Contributor

@sadym-chromium sadym-chromium commented Jul 8, 2025

First step addressing #776.


Preview | Diff

@sadym-chromium sadym-chromium force-pushed the sadym/emulation.setNetworkConditions branch from 909666e to 4b304a6 Compare July 8, 2025 19:17
@sadym-chromium sadym-chromium changed the title [NOT READY] emulation.setNetworkConditions [NOT READY] Emulate offline mode Jul 9, 2025
@sadym-chromium sadym-chromium force-pushed the sadym/emulation.setNetworkConditions branch from 3e9d492 to 7d5df6c Compare July 9, 2025 13:54
@sadym-chromium sadym-chromium force-pushed the sadym/emulation.setNetworkConditions branch 2 times, most recently from 5a54342 to 08b8e65 Compare July 23, 2025 13:58
@sadym-chromium sadym-chromium changed the title [NOT READY] Emulate offline mode emulation.setNetworkConditions Jul 23, 2025
@sadym-chromium sadym-chromium marked this pull request as ready for review July 23, 2025 14:22
Copy link
Contributor

@juliandescottes juliandescottes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we discuss this again with the working group (if it was discussed recently, I'm missing the summary) ?

@juliandescottes
Copy link
Contributor

Notes from the Working Group meeting:

18:33 sadym: feature requested by users is setting network conditions. Started with offline mode. Technically can be done with Network Interception. Will be difficult to specify bandwidth etc.
18:34 sadym: talking about offline: several aspects : network requests and navigator online. With network interception we cannot influence navigator online, bur we can handle requests
18:35 sadym: currently navigator online is defined in a way which should return false if the user can't reach the network. Unclear behavior
18:36 sadym: proposal is to add a hook is offline so that the html spec can call this to know what to return
18:36 q+
18:36 * Zakim sees jdescottes on the speaker queue
18:36 ack jdescottes
18:36 * Zakim sees no one on the speaker queue
18:37 jdescottes: hook for html spec sounds good to me, especially since we can't block all network for now
18:38 q+
18:38 * Zakim sees jimevans on the speaker queue
18:38 sadym: should we split or land everything in one PR
18:40 jimevans: can be more work, but I would prefer to see the full implementation landed at once. I would expect everything to behave as offline/online when setting this emulation.
18:40 sadym: sounds good

@sadym-chromium sadym-chromium force-pushed the sadym/emulation.setNetworkConditions branch 3 times, most recently from 2283b57 to 56e6e63 Compare August 18, 2025 15:30
@sadym-chromium sadym-chromium changed the title emulation.setNetworkConditions emulation.setNetworkConditions:offline Aug 18, 2025
@sadym-chromium sadym-chromium force-pushed the sadym/emulation.setNetworkConditions branch 3 times, most recently from 7e372ac to 3f3075d Compare August 18, 2025 16:19
@sadym-chromium
Copy link
Contributor Author

@juliandescottes @OrKoN could you please take another look?

@sadym-chromium sadym-chromium force-pushed the sadym/emulation.setNetworkConditions branch from 3f3075d to 2f3394e Compare August 20, 2025 15:01
@sadym-chromium
Copy link
Contributor Author

@juliandescottes PTAL

Copy link
Contributor

@juliandescottes juliandescottes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update, and sorry for the delay. Overall I think the update for BiDi looks good, but I'm not sure how we should treat this PR since we have a dependency on HTML and Fetch.

I prefer to let James or other people more used to the spec world comment on this, my feeling is that we might need at least some agreement on the other PRs that they are ok with the direction. We can also discuss it next wednesday during the meeting.

Copy link
Member

@jgraham jgraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently I made some comments a while ago and didn't submit them…


1. Let |emulated network conditions| be null.

1. If |command parameters|["<code>networkConditions</code>"] is not null and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now the check for type can just be an assert. I see you're trying to define this for extensibility although it does make the API rather odd in the short term, and the obvious extensions into network conditions seem like they're going to be rather challenging to standardise. I wonder if we'd be better with just a network.setOffline({contexts, userContexts, offline: <bool>}) command for now.

Copy link
Contributor Author

@sadym-chromium sadym-chromium Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't plan to extend for other network conditions (e.g. high-latency or low-bandwidth), I'd propose to:

  1. Move the method to emulation.setNetworkOffline, as it influences not only the network, but the navigator as well.
  2. Allow for only offline: true / null, as we cannot emulate being online when offline, we can only restore the default behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I believe that it still makes sense to keep it extendable and eventually introduce other conditions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I still feel like a separate command would have been the better design for now. The only advantage I see of a single command is that it will make it easier in the future to switch atomically from a "network offline" state to an online state with some other configuration. But that would be possible either way (e.g. by allowing the configuration to be set when offline, and applying it when online).

This would have the advantage of not making the existing protocol more complex in service of uncertain future requirements.

However since there is already general agreement about the approach here I don't consider it a blocker.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, thanks for the clarification! I imagine we can extend the emulated conditions with some vendor-specific types in the nearest future until the proper specification is landed.

@css-meeting-bot
Copy link
Member

The Browser Testing and Tools Working Group just discussed emulation.setNetworkConditions:offline.

The full IRC log of that discussion <tidoust> Topic: emulation.setNetworkConditions:offline
<tidoust> github: https://github.com//pull/948
<jgraham> q+
<tidoust> sadym: Current version of spec is that no network emulation is pretty much airplane mode.
<jgraham> ack next
<tidoust> jgraham: I was definitely imagining something like "what if the network goes down at this point", rather than a clean network disconnection.
<orkon> q+
<tidoust> ... What happens if you engage offline mode. What does the prior art look like? Closing connections gracefully? Or shutting them down?
<sadym> q+
<jgraham> ack next
<jdescottes> q+
<tidoust> orkon: We discussed this. If you go offline, usually it's not instant, you have timeouts on HTTP, TCP, etc. navigator.online does not report the status right away.
<tidoust> ... What we discussed is that switching would only apply to new requests.
<tidoust> ... This is a simpler model, and I don't see a strong use case for airplane mode where you emulate offline mode.
<tidoust> ... You want to check that, e.g., your service worker picks up things correctly.
<tidoust> ... It would be difficult to emulate the real circumstances for when you're going offline given the many ongoing connections that may be happening.
<jgraham> ack next
<tidoust> sadym: Emulate tunnel in the train vs. airplane is what we need to get consensus on, then.
<jgraham> q+
<jgraham> ack next
<tidoust> jdescottes: The situation in Firefox is that there are two ways to get offline.
<tidoust> ... Two inconsistent features, including one in dev tools.
<tidoust> ... I still think that we should do more than preventing next request. Just failing requests on beforeRequestSent is not enough.
<tidoust> ... Some applications may be relying on other signals to switch to offline mode.
<tidoust> ... Also, this PR depends on two other PRs, do we want to wait until these two PRs are reviewed?
<jgraham> ack next
<sadym> q+
<tidoust> jgraham: In most testing scenarios, I agree that simplifying things is probably enough.
<tidoust> ... I believe the current PR covers the needs.
<tidoust> ... In the context of the scripting API, we've sometimes landed updates even when the background is broken when there are inter-dependencies. Sometimes, we need to go back and clean up the other PRs.
<sadym> q+
<tidoust> Blaze: Webkit uses this online/offline marker to switch mode.
<tidoust> ... That should align well with this.
<jgraham> ack next
<tidoust> ... I don't see any blocker.

@sadym-chromium sadym-chromium force-pushed the sadym/emulation.setNetworkConditions branch from 86e4787 to ccaddea Compare September 12, 2025 11:40
@sadym-chromium
Copy link
Contributor Author

@jgraham could you please take another look?

@sadym-chromium
Copy link
Contributor Author

@juliandescottes @jgraham friendly ping

Copy link
Contributor

@juliandescottes juliandescottes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Maksim, looks fine to me, just a couple of questions.


1. Let |user context| be |top-level traversable|'s [=associated user context=].

1. For each |session| in [=active BiDi sessions=]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we store the conditions on the session or on the remote end?
With the per session approach, the first session to be checked always wins. Whereas if it's per remote end, the last condition set wins, which feels easier to manage for users than (arbitrary) session order?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion here, as currently we don't support multiple sessions. For now I changed the spec, so that we check all sessions' navigables, then user contexts, and then default settings.

The steps to <dfn>get emulated network conditions</dfn> given |related navigables|
are:

1. For each |navigable| of |related navigables|:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: probably not important as long as we can only disable, but I'm wondering about scenarios where later we could support other network conditions eg throttling.

If navigable 1 is throttled and navigable 2 is offline, what should we do? We should probably defer that discussion to whenever we implement more conditions, but still curious if you have any thoughts about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: probably not important as long as we can only disable, but I'm wondering about scenarios where later we could support other network conditions eg throttling.

If navigable 1 is throttled and navigable 2 is offline, what should we do? We should probably defer that discussion to whenever we implement more conditions, but still curious if you have any thoughts about this.

This spec version defines the behavior as "the first created navigable wins". This scenario happens for shared workers. However IDK what exactly Chromium does in this case, and I don't have a strong opinion what it should do.

@sadym-chromium sadym-chromium force-pushed the sadym/emulation.setNetworkConditions branch from 53a2695 to c419406 Compare October 6, 2025 08:17
@sadym-chromium sadym-chromium requested a review from jgraham October 7, 2025 07:48
@sadym-chromium sadym-chromium merged commit 18639ef into main Oct 7, 2025
5 checks passed
@sadym-chromium sadym-chromium deleted the sadym/emulation.setNetworkConditions branch October 7, 2025 09:30
github-actions bot added a commit that referenced this pull request Oct 7, 2025
SHA: 18639ef
Reason: push, by sadym-chromium

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@whimboo
Copy link
Contributor

whimboo commented Oct 13, 2025

@sadym-chromium Will you also work on the wpt tests whenever you are going to work on supporting this feature?

@sadym-chromium
Copy link
Contributor Author

@sadym-chromium Will you also work on the wpt tests whenever you are going to work on supporting this feature?

The wpr tests are landed

@whimboo
Copy link
Contributor

whimboo commented Oct 13, 2025

Ah, there was no link to web-platform-tests/wpt#55300 in this PR. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants