Skip to content

feat(webview): track same-document navigations#41414

Merged
dcrousso merged 1 commit into
microsoft:mainfrom
dcrousso:fix-WKWebView-same-document-navigation
Jun 22, 2026
Merged

feat(webview): track same-document navigations#41414
dcrousso merged 1 commit into
microsoft:mainfrom
dcrousso:fix-WKWebView-same-document-navigation

Conversation

@dcrousso

Copy link
Copy Markdown
Contributor

Page.navigatedWithinDocument does not exist in the upstream WebKit inspector protocol

instead, use JS "popstate", "hashchange", and "currententrychange" events to track that

note that this involves leveraging the existing console.debug() communication method

@dcrousso dcrousso requested review from pavelfeldman and yury-s June 22, 2026 19:00
@dcrousso dcrousso added the CQ1 label Jun 22, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@pavelfeldman

Copy link
Copy Markdown
Member

In https://github.com/microsoft/playwright/pull/41409/changes you are using window.naviation. If it exists, do we need to patch the methods or listeners will work?

@dcrousso

Copy link
Copy Markdown
Contributor Author

it only uses navigation.canGoBack()/navigation.canGoForward() which are readonly checks of the state

we have to swizzle history.pushState()/history.popState() because they silently adjust the current URL (i.e. they don't dispatch "popstate"/"hashchange" events)

this is not necessary for the Navigation API because all methods that modify the current URL will dispatch a "currententrychange" event

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "tests 2"

1 fatal errors, not part of any test
10 failed
❌ [firefox-page] › page/workers.spec.ts:40 › should emit created and destroyed events @tracing-firefox
❌ [firefox-library] › library/defaultbrowsercontext-2.spec.ts:104 › should accept relative userDataDir @firefox-macos-15-large
❌ [firefox-library] › library/defaultbrowsercontext-2.spec.ts:111 › should restore state from userDataDir @firefox-macos-15-large
❌ [firefox-library] › library/defaultbrowsercontext-2.spec.ts:139 › should create userDataDir if it does not exist @firefox-macos-15-large
❌ [firefox-library] › library/inspector/cli-codegen-2.spec.ts:543 › cli codegen › should auto-generate toBeVisible @firefox-macos-15-large
❌ [firefox-library] › library/inspector/cli-codegen-csharp.spec.ts:202 › should not print context options method override in nunit if no options were passed @firefox-macos-15-large
❌ [firefox-library] › library/inspector/cli-codegen-test.spec.ts:20 › should print the correct imports and context options @firefox-macos-15-large
❌ [firefox-page] › page/workers.spec.ts:40 › should emit created and destroyed events @firefox-macos-15-large
❌ [firefox-page] › page/workers.spec.ts:40 › should emit created and destroyed events @firefox-windows-latest
❌ [firefox-page] › page/workers.spec.ts:40 › should emit created and destroyed events @firefox-macos-15-xlarge

41 flaky ⚠️ [chromium-library] › library/chromium/chromium.spec.ts:177 › serviceWorker(), and fromServiceWorker() work `@tracing-chromium`
⚠️ [chromium-library] › library/defaultbrowsercontext-1.spec.ts:89 › should support viewport option `@msedge-dev-windows-latest`
⚠️ [chromium-library] › library/video.spec.ts:456 › screencast › should be 800x600 with null viewport `@msedge-dev-windows-latest`
⚠️ [chromium-page] › page/workers.spec.ts:63 › should have timestamp on worker console messages `@msedge-dev-windows-latest`
⚠️ [chromium-library] › library/video.spec.ts:456 › screencast › should be 800x600 with null viewport `@chrome-ubuntu-22.04`
⚠️ [chromium-library] › library/video.spec.ts:456 › screencast › should be 800x600 with null viewport `@msedge-windows-latest`
⚠️ [chromium-page] › page/workers.spec.ts:63 › should have timestamp on worker console messages `@chromium-windows-latest`
⚠️ [chromium-library] › library/browsertype-connect.spec.ts:189 › launchServer › should ignore page.pause when headed `@chromium-macos-15-large`
⚠️ [chromium-library] › library/heap.spec.ts:203 › cycle handles `@chromium-macos-15-large`
⚠️ [chromium-library] › library/trace-viewer.spec.ts:1850 › should not leak recorders `@chromium-macos-15-large`
⚠️ [chromium-library] › library/chromium/chromium.spec.ts:434 › should produce network events, routing, and annotations for Service Worker (advanced) `@chromium-macos-14-xlarge`
⚠️ [chromium-library] › library/chromium/chromium.spec.ts:371 › should produce network events, routing, and annotations for Service Worker `@chromium-macos-15-xlarge`
⚠️ [chromium-library] › library/video.spec.ts:680 › screencast › should capture full viewport on hidpi `@chromium-macos-15-xlarge`
⚠️ [chromium-library] › library/video.spec.ts:456 › screencast › should be 800x600 with null viewport `@chrome-windows-latest`
⚠️ [chromium-library] › library/har-websocket.spec.ts:235 › should attach websocket messages `@chrome-beta-ubuntu-22.04`
⚠️ [chromium-library] › library/video.spec.ts:456 › screencast › should be 800x600 with null viewport `@chrome-beta-ubuntu-22.04`
⚠️ [firefox-library] › library/browsertype-connect.spec.ts:530 › launchServer › should save videos to artifactsDir `@firefox-macos-15-large`
⚠️ [firefox-library] › library/defaultbrowsercontext-2.spec.ts:166 › should have default URL when launching browser `@firefox-macos-15-large`
⚠️ [firefox-library] › library/defaultbrowsercontext-2.spec.ts:180 › should have passed URL when launching with ignoreDefaultArgs: true `@firefox-macos-15-large`
⚠️ [firefox-library] › library/defaultbrowsercontext-2.spec.ts:253 › should support har option `@firefox-macos-15-large`
⚠️ [firefox-library] › library/defaultbrowsercontext-2.spec.ts:264 › user agent is up to date `@firefox-macos-15-large`
⚠️ [firefox-library] › library/har.spec.ts:990 › should record resource type `@firefox-macos-15-large`
⚠️ [firefox-library] › library/hit-target.spec.ts:259 › should not click an element overlaying iframe with the target `@firefox-macos-15-large`
⚠️ [firefox-library] › library/inspector/cli-codegen-1.spec.ts:53 › cli codegen › should double click `@firefox-macos-15-large`
⚠️ [firefox-library] › library/inspector/cli-codegen-1.spec.ts:250 › cli codegen › should work with TrustedTypes `@firefox-macos-15-large`
⚠️ [firefox-library] › library/inspector/cli-codegen-3.spec.ts:185 › cli codegen › should generate frame locators (3) `@firefox-macos-15-large`
⚠️ [firefox-library] › library/inspector/cli-codegen-csharp.spec.ts:28 › should print the correct imports and context options `@firefox-macos-15-large`
⚠️ [firefox-library] › library/inspector/cli-codegen-csharp.spec.ts:208 › should print context options method override in nunit if options were passed `@firefox-macos-15-large`
⚠️ [firefox-library] › library/inspector/cli-codegen-csharp.spec.ts:208 › should print context options method override in xunit if options were passed `@firefox-macos-15-large`
⚠️ [firefox-library] › library/inspector/cli-codegen-java.spec.ts:125 › should print a valid basic program in junit `@firefox-macos-15-large`
⚠️ [firefox-library] › library/inspector/cli-codegen-python.spec.ts:76 › should save the codegen output to a file if specified `@firefox-macos-15-large`
⚠️ [firefox-library] › library/proxy.spec.ts:306 › should use socks proxy `@firefox-macos-15-large`
⚠️ [firefox-library] › library/proxy.spec.ts:316 › should use socks proxy in second page `@firefox-macos-15-large`
⚠️ [firefox-library] › library/proxy.spec.ts:369 › should use SOCKS proxy for websocket requests `@firefox-macos-15-large`
⚠️ [firefox-library] › library/browsercontext-viewport.spec.ts:132 › should set both screen and viewport options `@firefox-macos-15-xlarge`
⚠️ [firefox-library] › library/screenshot.spec.ts:213 › page screenshot › should not hang when event loop is blocked `@firefox-macos-15-xlarge`
⚠️ [webkit-library] › library/page-clock.spec.ts:537 › AbortSignal.timeout `@tracing-webkit`
⚠️ [webkit-library] › library/proxy.spec.ts:42 › should use proxy for second page `@tracing-webkit`
⚠️ [webkit-library] › library/inspector/cli-codegen-3.spec.ts:979 › cli codegen › should record when manual popover with fullscreen backdrop is open `@webkit-macos-15-large`
⚠️ [webkit-page] › page/page-set-input-files.spec.ts:38 › should upload a folder `@webkit-macos-15-large`
⚠️ [android-page] › page/selectors-frame.spec.ts:209 › should click in lazy iframe

99773 passed, 4308 skipped


Merge workflow run.

@dcrousso dcrousso force-pushed the fix-WKWebView-same-document-navigation branch from 69819e5 to 355a104 Compare June 22, 2026 20:23
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

`Page.navigatedWithinDocument` does not exist in the upstream WebKit inspector protocol

instead, use JS `"popstate"`, `"hashchange"`, and `"currententrychange"` events to track that

note that this involves leveraging the existing `console.debug()` communication method
@dcrousso dcrousso force-pushed the fix-WKWebView-same-document-navigation branch from 355a104 to a41a0e9 Compare June 22, 2026 21:59
@dcrousso

Copy link
Copy Markdown
Contributor Author

im going to investigate the test timeouts separately

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "MCP"

7380 passed, 1122 skipped


Merge workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "tests 1"

3 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
❌ [firefox-page] › page/workers.spec.ts:40 › should emit created and destroyed events @firefox-ubuntu-22.04-node20

6 flaky ⚠️ [chromium-library] › library/popup.spec.ts:260 › should not throw when click closes popup `@chromium-ubuntu-22.04-arm-node20`
⚠️ [chromium-library] › library/video.spec.ts:717 › screencast › should work with video+trace `@chromium-ubuntu-22.04-arm-node20`
⚠️ [chromium-library] › library/video.spec.ts:717 › screencast › should work with video+trace `@realtime-time-library-chromium-linux`
⚠️ [chromium-library] › library/popup.spec.ts:260 › should not throw when click closes popup `@chromium-ubuntu-22.04-node24`
⚠️ [chromium-library] › library/tracing.spec.ts:430 › should produce screencast frames crop `@chromium-ubuntu-22.04-node20`
⚠️ [playwright-test] › ui-mode-test-progress.spec.ts:250 › should show live trace for serial `@windows-latest-node22`

48923 passed, 1142 skipped


Merge workflow run.

@dcrousso

Copy link
Copy Markdown
Contributor Author

im gonna investigate the issue with tests/page/page-set-content.spec.ts:153:3 › should handle timeout properly 2 separately since i can reproduce that locally without these chanages

@dcrousso dcrousso merged commit 36ef511 into microsoft:main Jun 22, 2026
52 of 56 checks passed
@dcrousso dcrousso deleted the fix-WKWebView-same-document-navigation branch June 22, 2026 23:12
@dcrousso

Copy link
Copy Markdown
Contributor Author

test timeout fixed in #41416

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants