Skip to content

[Bug]: browserContext.setOffline(true) does not affect WebRTC media (verified on both host and TURN relay paths) — docs scope note proposed #42623

Closed

Description

Version

1.62.1

Steps to reproduce

  1. Launch Chromium and create two separate browser contexts with one page each.

  2. Establish an RTCPeerConnection between the two pages with an active audio
    track (generated via Web Audio, so no getUserMedia is needed in headless).
    Exchange SDP non-trickle through Node, so no signaling WebSocket remains
    open to be affected by setOffline.

  3. On the receiving page, poll getStats() once per second; record
    inbound-rtp.bytesReceived and the iceConnectionState.

  4. Call setOffline(true) on the receiving page's context.

  5. Verify HTTP is cut in that context: fetch() and XMLHttpRequest from the
    page now fail immediately (observed: within 10 ms).

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

  1. setOffline(true) disrupts the WebRTC transport as well: packets stop
    flowing, bytesReceived plateaus, and iceConnectionState eventually
    transitions to disconnected / failed — consistent with what "the
    browser context is offline" implies; or

  2. 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), the setOffline documentation states it explicitly, e.g.:
    "setOffline does 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; XMLHttpRequest within 0.00 s.
  • inbound-rtp.bytesReceived continued increasing for the full 30 s offline
    window: 16,160 → 138,065 bytes (+1,525 packets), strictly monotonic at 1 s
    sampling.
  • iceConnectionState remained connected at every sample.

Run 2 — TURN relay path, non-loopback address:

  • Local coturn 4.7.0, iceTransportPolicy: 'relay'. Selected candidate pair
    verified before measuring: local relay 10.0.0.119:51022 (udp) ↔ remote
    relay 10.0.0.119:51028 (udp); only relay candidates gathered.
  • After setOffline(true) on the receiving context: fetch() failed within
    0.01 s; XMLHttpRequest within 0.00 s.
  • inbound-rtp.bytesReceived continued 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).
  • iceConnectionState remained connected at 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 setOffline documentation
    (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. setOffline looks 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

  1. jaynirmal15 commented on Sep 8, 2026

    @jaynirmal15
    Author

    Thank you, Pavel Feldman (@pavelfeldman) — exactly what was needed. 🙏

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions