Skip to content

emulation.setNetworkConditions #948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sadym-chromium
Copy link
Contributor

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

Addressing #776

Implement offline emulation.

Out of scope: HTML navigator.onLine.


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 from 7d5df6c to 5a54342 Compare July 23, 2025 13:01
@sadym-chromium sadym-chromium force-pushed the sadym/emulation.setNetworkConditions branch 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) ?

Comment on lines +9244 to +9250
1. Let |emulated network conditions| be the result of
[=get emulated network conditions=] with |related navigables|.

1. If |emulated network conditions| is not null and
|emulated network conditions|'s [=emulated-network-conditions-struct/offline=] is
true, return ([=network error=], "<code>complete</code>").

Copy link
Contributor

@juliandescottes juliandescottes Jul 31, 2025

Choose a reason for hiding this comment

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

What is the added value of an offline emulation which only rejects on beforeRequestSent. It seems you can easily implement this with addIntercept + failRequest? Even if we ignore navigator.online, an offline mode should impact ongoing requests, websockets, allow you to test service workers etc... I feel like a limited feature like this would be more confusing than anything else?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was under impression that this was discussed in the WG? I do not think the offline mode should apply to ongoing requests and with this it should apply to web sockets and service worker requests as they have to start via fetch? The advantage is that you do no pay the cost of interception and have a dedicated command that can be extended with further aspects specific to the network condition emulation. The question I would have if this allows successfully testing the offline mode behavior of the browser which is probably a bit more than failing the network requests?

Copy link
Contributor

@juliandescottes juliandescottes Jul 31, 2025

Choose a reason for hiding this comment

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

I was under impression that this was discussed in the WG?

I thought so as well, but I wanted to check the details and I can't find any summary for this discussion. So I'm just giving my feedback based on what is currently proposed. I couldn't find a matching topic in the last 6 meetings, but maybe this was discussed informally?

For service workers, I would need to check in details. I was thinking about a fetch request which gets captured by an already registered service worker, returning a response from the cache. This should still work in offline mode, but not sure that's the case here?

For websocket, is fetch used for anything but establishing the connection at https://websockets.spec.whatwg.org/#concept-websocket-establish ? I was thinking about ws messages on an already open websocket.

The question I would have if this allows successfully testing the offline mode behavior of the browser which is probably a bit more than failing the network requests?

I think the answer to this is no, but I don't know if the offline mode is completely specified.

But if the WG agreed to have something that only blocks new fetch requests as an offline mode, I don't mean to block the PR (would be great if I could find the discussion though :) )

Copy link
Contributor

Choose a reason for hiding this comment

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

I was not attending unfortunately so I do not know for sure :)

Copy link
Member

Choose a reason for hiding this comment

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

I don't remember such a discussion and broadly agree with Julian's concerns here; I'd certainly expect that in offline mode navigatior.onLine should be false, and for the offline event to fire when the state changes. I also agree it would be extremely surprising if e.g. open websockets (or server sent events eventsources) continue to work in "offline" mode.

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.

4 participants