Skip to content

New Feature: Migrate network emulation to Network.emulateNetworkConditionsByRule (#15508) - #3616

Merged
kblok merged 1 commit into
masterfrom
implement-upstream-change-15508
Oct 15, 2026
Merged

kblok merged 1 commit into
masterfrom
implement-upstream-change-15508

Conversation

@kblok

@kblok kblok commented Oct 14, 2026

Copy link
Copy Markdown
Member

Implements changes from puppeteer/puppeteer#15508

🤖 Generated with Claude Code

…#15508)

Implements puppeteer/puppeteer#15508

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@kblok
kblok merged commit 14fa1af into master Oct 15, 2026
26 of 28 checks passed
@kblok
kblok deleted the implement-upstream-change-15508 branch October 15, 2026 11:18
lahma added a commit to sebastienros/jint that referenced this pull request Oct 17, 2026
…ate and emulateNetworkConditionsByRule (#4292)

* Answer PuppeteerSharp 25.14's offline mode: Network.overrideNetworkState and emulateNetworkConditionsByRule

PuppeteerSharp 25.14 (hardkoded/puppeteer-sharp#3616, porting puppeteer/puppeteer#15508)
moved SetOfflineModeAsync and EmulateNetworkConditionsAsync off the deprecated
Network.emulateNetworkConditions onto the pair Chrome replaced it with:
Network.overrideNetworkState, then Network.emulateNetworkConditionsByRule. Both
answered -32601 here, and the failure was silent because PuppeteerSharp's
NetworkManager.CanIgnoreError swallows any error whose message contains
"wasn't found" - Chrome's own -32601 wording - so the first command's
rejection was dropped and the second was never sent. The page stayed online.

Both commands are now implemented and mapped the way Chrome maps them:

- emulateNetworkConditionsByRule is the transport. It writes the same offline
  state emulateNetworkConditions always wrote, replacing it rather than merging,
  so the last of the two to be sent decides and an empty list goes back online.
  A global entry (empty urlPattern) is honoured; the first entry wins and the
  deprecated top-level offline overrides each entry's own, as in Chrome. An
  entry scoped to a URL is refused with -32000 rather than applied to every
  request or to none. One rule id is minted per entry.
- overrideNetworkState is the navigator. navigator.onLine now reads the page's
  EmulationState.Offline instead of always answering true, and a change fires
  HTML's offline/online event at the window. It fails no request.
- emulateNetworkConditions keeps working and now writes both halves, which is
  what Chrome does (one global rule plus the renderer's navigator override), so
  clearing through either form leaves nothing set through the other.

The PuppeteerSharp pin moves to 25.14.0 in the same change, so
PuppeteerSetsHeadersCookiesAndTakesThePageOffline proves the fix; it now also
turns offline back off and reads navigator.onLine. The two methods move from
"none" to "page" in HandshakeReplayTests.Absent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YVwU18SgMKKzYrrCh4TMpT

* Pin what PuppeteerSharp's BlockList hears from the URL-scoped refusal

ConnectOptions.BlockList and Allowlist are the PuppeteerSharp path that sends
URL-scoped Network.emulateNetworkConditionsByRule entries, from
ChromeTargetManager.MaybeSetupNetworkBlockListAsync on every attached target.
That method catches every exception and logs "Failed to setup network block
list", so the -32000 refusal reaches the client's log and never ConnectAsync,
NewPageAsync or GoToAsync. Before the command was answered, its -32601 took the
same catch (it is not NetworkManager's CanIgnoreError path).

PuppeteerConnectsWithABlockListAndHearsTheUrlScopedRulesRefused connects with a
block list through a recording ILoggerFactory, navigates to an allowed URL, has
PuppeteerSharp's own pre-send check refuse the blocked one, and waits for the
refusal's reason in the client's log. NetworkDomain's remarks name the path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YVwU18SgMKKzYrrCh4TMpT

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant