Skip to content

fix(chromium): replay execution contexts when connecting to Android WebView - #42447

Merged
Pavel Feldman (pavelfeldman) merged 1 commit into
microsoft:mainfrom
pavelfeldman:webview-cdp-runtime-replay
Aug 28, 2026
Merged

fix(chromium): replay execution contexts when connecting to Android WebView#42447
Pavel Feldman (pavelfeldman) merged 1 commit into
microsoft:mainfrom
pavelfeldman:webview-cdp-runtime-replay

Conversation

@pavelfeldman

@pavelfeldman Pavel Feldman (pavelfeldman) commented Aug 28, 2026

Copy link
Copy Markdown
Member

Android WebView's devtools endpoint sometimes acknowledges Runtime.enable without replaying the pre-existing execution contexts, leaving the main world unknown forever and any page interaction hanging.

After frame session initialization, if no default (main world) execution context has been reported, cycle Runtime.disable/Runtime.enable until it shows up (250ms between attempts, bounded at 10). A healthy endpoint pays nothing: replayed executionContextCreated events arrive before the Runtime.enable response on the ordered transport, so the first check exits the loop immediately. Re-announced contexts from the re-enable are already handled by frame.contextCreated, which replaces an existing world context.

The workaround is gated on a new internal isWebView connect-over-CDP option so regular Chrome over CDP is unaffected; Playwright's own Android webview attach (AndroidDevice.connectToWebView) sets the bit automatically, while Clank launch does not.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

…ebView

Android WebView's devtools endpoint sometimes acknowledges Runtime.enable
without replaying the pre-existing execution contexts, leaving the main
world unknown forever. Cycle Runtime.disable/enable until the default
context is reported.

This behavior is gated on a new internal isWebView connect option, so
regular Chrome over CDP is unaffected. Playwright's own Android webview
attach sets the bit automatically.
// Android WebView's devtools endpoint sometimes acknowledges Runtime.enable
// without replaying the pre-existing execution contexts. Cycle
// Runtime.disable/enable until the default context is reported.
for (let attempt = 0; attempt < 10; ++attempt) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We need a more reliable mechanism, I'm pretty sure 10x won't be enough in some cases!

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "tests 1"

1 flaky ⚠️ [firefox-page] › page/page-emulate-media.spec.ts:144 › should keep reduced motion and color emulation after reload `@firefox-ubuntu-22.04-node20`

51252 passed, 1240 skipped


Merge workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "MCP"

8259 passed, 1361 skipped


Merge workflow run.

@pavelfeldman
Pavel Feldman (pavelfeldman) merged commit eca9e03 into microsoft:main Aug 28, 2026
45 checks passed
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.

2 participants