Repository navigation
Description
Version
1.62.1
Steps to reproduce
-
Launch Chromium and create two separate browser contexts with one page each.
-
Establish an
RTCPeerConnectionbetween the two pages with an active audio
track (generated via Web Audio, so nogetUserMediais needed in headless).
Exchange SDP non-trickle through Node, so no signaling WebSocket remains
open to be affected bysetOffline. -
On the receiving page, poll
getStats()once per second; record
inbound-rtp.bytesReceivedand theiceConnectionState. -
Call
setOffline(true)on the receiving page's context. -
Verify HTTP is cut in that context:
fetch()andXMLHttpRequestfrom the
page now fail immediately (observed: within 10 ms). -
Continue polling for 30 seconds.
Observed: bytesReceived continues increasing at an unchanged rate for the
full 30 s window and iceConnectionState remains connected throughout.
Relay-path variant (rules out loopback special-casing): repeat the above
with a local coturn server and iceTransportPolicy: 'relay', on a
non-loopback address. Verify via getStats() that the selected candidate pair
is relay-type before measuring (in my runs: local relay 10.0.0.119:51022/udp,
remote relay 10.0.0.119:51028/udp; only relay candidates gathered). Result
is identical: media continues at the baseline rate (~4.05 kB/s), the selected
pair remains relay-type at every sample, and iceConnectionState never leaves
connected.
Expected behavior
One of the following:
-
setOffline(true)disrupts the WebRTC transport as well: packets stop
flowing,bytesReceivedplateaus, andiceConnectionStateeventually
transitions todisconnected/failed— consistent with what "the
browser context is offline" implies; or -
If this scope limit is by design (setOffline gates the intercepted network
stack — fetch/XHR/WebSocket — while WebRTC's UDP sockets are managed
outside it), thesetOfflinedocumentation states it explicitly, e.g.:
"setOfflinedoes not affect WebRTC media (UDP); use OS- or network-level
interruption to test WebRTC failure paths."
Either resolution works for users; the current state — offline emulation that
silently exempts WebRTC, with no documentation of the exemption — is the
problem, because it makes setOffline an unreliable primitive for WebRTC
failure and reconnection testing and the failure mode is invisible (the test
passes while testing nothing).
Actual behavior
After setOffline(true), HTTP traffic in the context is cut immediately, but
established WebRTC peer connections are completely unaffected — media
continues to flow at an unchanged rate and ICE never leaves connected.
Confirmed on 2026-09-08, two independent runs:
Run 1 — loopback host candidates (no ICE servers):
fetch()failed within 0.01 s;XMLHttpRequestwithin 0.00 s.inbound-rtp.bytesReceivedcontinued increasing for the full 30 s offline
window: 16,160 → 138,065 bytes (+1,525 packets), strictly monotonic at 1 s
sampling.iceConnectionStateremainedconnectedat every sample.
Run 2 — TURN relay path, non-loopback address:
- Local coturn 4.7.0,
iceTransportPolicy: 'relay'. Selected candidate pair
verified before measuring: local relay10.0.0.119:51022(udp) ↔ remote
relay10.0.0.119:51028(udp); onlyrelaycandidates gathered. - After
setOffline(true)on the receiving context:fetch()failed within
0.01 s;XMLHttpRequestwithin 0.00 s. inbound-rtp.bytesReceivedcontinued increasing for the full 30 s window:
15,890 → 137,957 bytes (+122,067 bytes, +1,525 packets), strictly monotonic
at 1 s sampling, rate unchanged from the pre-offline baseline (~4.05 kB/s).iceConnectionStateremainedconnectedat every sample; the selected
pair remained relay-type throughout. ICE transitions for the entire run:
["checking", "connected"].
The likely mechanism: setOffline operates on the network stack Playwright
intercepts (fetch/XHR/WebSocket), while WebRTC's UDP sockets are managed
separately and never pass through that layer.
Workaround for anyone needing deterministic WebRTC failure injection
today: interrupt the path outside the browser. I pause a local coturn TURN
relay with SIGSTOP, which severs media reliably and reversibly with precise
timing. Implementation: https://github.com/jaynirmal15/webrtc-recovery-harness
Proposal: if maintainers confirm this is by design, I am happy to submit a
docs PR adding a one-line scope note to setOffline and the network
emulation guide.
Additional context
-
I searched existing issues before filing (
setOffline WebRTC,
setOffline peer connection,setOffline UDP,offline mode RTCPeerConnection,network emulation WebRTC, open and closed): no prior
issue documents this behavior or its scope limit. [Question] Does playwright support browser network emulation? #3393 asks about network
emulation generally (closed 2020) but does not touch setOffline or WebRTC. -
The current
setOfflinedocumentation
(https://playwright.dev/docs/api/class-browsercontext#browser-context-set-offline)
says only that it emulates the context being offline, with no WebRTC/UDP
scope note — so the gap exists regardless of whether the behavior itself is
intended. -
Why this matters in practice: Playwright is increasingly used to test
WebRTC applications end to end, and connection-loss/reconnection paths are
exactly what such tests target.setOfflinelooks like the natural
primitive for that, and the failure mode is silent — the app under test
never loses media, reconnection logic never triggers, and the test passes
while exercising nothing. I lost real debugging time to this while building
a WebRTC failure-testing harness before isolating the cause. -
Both verification runs above used non-trickle SDP exchanged through Node
specifically so that no signaling WebSocket remains open — ruling out the
interpretation that the peer connection survives only because signaling
was already established. -
Happy to provide the standalone repro script, run additional variants
(Firefox, WebKit, data-channel-only), or submit the docs PR described
above.
Environment
- Playwright: 1.62.1 (package.json declares ^1.54.2)
- Chromium: Chrome for Testing 151.0.7922.34 (Playwright chromium v1234, mac-x64)
- Firefox: 153.0 (Playwright firefox v1538) — installed; verification runs used Chromium
- OS: macOS 15.7.9 (24G830), Darwin 24.6.0, x86_64
- Node: v24.10.0
- coturn: 4.7.0 (local TURN relay for the relay-path run; relay-only ICE)
Activity
jaynirmal15 commentedon Sep 8, 2026
Thank you, Pavel Feldman (@pavelfeldman) — exactly what was needed. 🙏