Skip to content

fix(networkidle): do not wait for open EventSource (SSE) connections#41514

Open
mxschmitt wants to merge 1 commit into
microsoft:mainfrom
mxschmitt:fix/networkidle-sse
Open

fix(networkidle): do not wait for open EventSource (SSE) connections#41514
mxschmitt wants to merge 1 commit into
microsoft:mainfrom
mxschmitt:fix/networkidle-sse

Conversation

@mxschmitt

Copy link
Copy Markdown
Contributor

Server-sent events (EventSource, text/event-stream) keep the HTTP response open indefinitely, so the browser never reports the request as finished. Because such a request stayed in the per-frame inflight set, the network idle timer never started and waitUntil: 'networkidle' / waitForLoadState('networkidle') would hang until the navigation timeout on any page that opens an EventSource.

This excludes eventsource requests from the network idle inflight set, the same way favicons are already excluded and WebSockets are tracked separately. The resource type is known at request-start time across all three backends, so the connection no longer gates networkidle.

Added regression tests in page-network-idle.spec.ts (goto and setContent) that hang without the fix and pass with it on Chromium, Firefox and WebKit.

Fixes #41513

Server-sent events (EventSource, text/event-stream) keep the HTTP
response open indefinitely, so the browser never reports the request as
finished. Because such a request stayed in the per-frame inflight set,
the network idle timer never started and `waitUntil: 'networkidle'` /
`waitForLoadState('networkidle')` would hang until the navigation
timeout on any page that opens an EventSource.

Exclude `eventsource` requests from the network idle inflight set, the
same way favicons are already excluded and WebSockets are tracked
separately. The resource type is known at request-start time across all
three backends, so the connection no longer gates networkidle.

Closes microsoft#37226
@github-actions

Copy link
Copy Markdown
Contributor

Test results for "MCP"

2 failed
❌ [chrome] › mcp/http.spec.ts:349 › client should receive list roots request @mcp-ubuntu-latest-chrome
❌ [firefox] › mcp/annotate.spec.ts:230 › should capture annotations via show --annotate @mcp-windows-latest-firefox

7446 passed, 1132 skipped


Merge workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "tests 1"

2 failed
❌ [chromium-library] › library/browsercontext-add-init-script.spec.ts:28 › should work without navigation, after all bindings @chromium-ubuntu-22.04-arm-node20
❌ [chromium-library] › library/browsercontext-expose-function.spec.ts:77 › should be callable from-inside addInitScript @chromium-ubuntu-22.04-arm-node20

4 flaky ⚠️ [chromium-library] › library/chromium/chromium.spec.ts:211 › should intercept service worker requests (main and within) `@chromium-ubuntu-22.04-arm-node20`
⚠️ [firefox-library] › library/defaultbrowsercontext-1.spec.ts:89 › should support viewport option `@firefox-ubuntu-22.04-node20`
⚠️ [firefox-library] › library/heap.spec.ts:223 › should not leak workers `@firefox-ubuntu-22.04-node20`
⚠️ [firefox-library] › library/inspector/cli-codegen-aria.spec.ts:87 › should update aria snapshot highlight `@firefox-ubuntu-22.04-node20`

44416 passed, 1071 skipped


Merge workflow run.

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.

[Bug]: networkidle never resolves when the page keeps an EventSource (SSE) connection open

1 participant