Skip to content

fix(tauri): reset the frame context when switching windows - #559

Merged
goosewobbler merged 1 commit into
mainfrom
fix/frame-context-window-switch
Aug 1, 2026
Merged

fix(tauri): reset the frame context when switching windows#559
goosewobbler merged 1 commit into
mainfrom
fix/frame-context-window-switch

Conversation

@goosewobbler

Copy link
Copy Markdown
Contributor

Description

Split out of #532, with attribution to @abu0306 — that PR fixes this as a side effect of child-webview support, but the bug is independent of the feature and present on main today.

The bug

switch_to_window updates the current window and leaves the frame stack alone:

// window.rs on main
session.current_window = request.handle;   // frame_context never cleared

W3C Switch To Window selects the target window's top-level browsing context. Because the stack survives, wrap_script_for_frame_context keeps wrapping every later command to descend doc.querySelectorAll('iframe, frame')[i] once per stack entry — so after switchToWindow(B) while inside a frame of A, scripts and element lookups in B walk into whatever happens to sit at that index in B. Wrong content, or an error.

Nothing in the tauri e2e suite calls switchToFrame (grep returns nothing), which is why this has gone unnoticed.

The fix

Session::switch_to_window advances a browsing-context generation and clears the frame stack in one step, and frame commits are validated against that generation before they are applied. That also closes a TOCTOU: switch_to_frame validates via the executor across an await, and a concurrent window switch landing in that window previously pushed a frame onto the wrong window.

Adapted from #532 in one respect — has_window_label is implemented over the stable webview_windows() rather than the unstable-gated webviews(), so this carries none of that PR's Tauri feature requirements.

Also refreshes the stale fixture Cargo.lock: it still pinned tauri-plugin-wdio / tauri-plugin-wdio-webdriver at 1.0.0 while their manifests say 1.2.0, so any fixture build left the tree dirty. Bundled here rather than as a third PR since it comes from the same source.

Deliberately left in #532

The no_such_window guard on get_window_handle and everything child-webview specific.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Scope

  • scope:tauri - Tauri service and plugin

Testing

  • cargo test23 passed (up from 15): 6 new commit_frame_context cases and 2 new switch_to_window cases
  • cargo clippy --all-targets -- -D warnings — clean, modulo the two pre-existing violations on main that ci(rust): run clippy on the first-party Rust crates #557 fixes
  • rustfmt --edition 2021 --check — clean on both changed Rust files

🤖 Generated with Claude Code

https://claude.ai/code/session_01CsgeivZCqduTQmWK55zqiT

Split out of #532, which fixes this as a side effect of child-webview support.
The bug is independent of that feature and present on main today.

`switch_to_window` set `current_window` and left `frame_context` untouched. W3C
Switch To Window selects the target window's *top-level* browsing context, but
because the stack survived, `wrap_script_for_frame_context` kept wrapping every
subsequent command to descend `doc.querySelectorAll('iframe, frame')[i]` — so
after switching out of a frame, scripts and element lookups in the new window
walked into whatever sat at that index there. Nothing in the tauri e2e suite
exercises switchToFrame, which is why it went unnoticed.

`Session::switch_to_window` now advances a browsing-context generation and
clears the frame stack in one step, and frame commits are validated against
that generation: a switch landing during the executor's frame validation no
longer pushes a frame onto the wrong window.

Also refreshes the stale fixture Cargo.lock (it still pinned the plugin crates
at 1.0.0 while their manifests say 1.2.0, so any fixture build dirtied it).

Co-authored-by: abu0306 <abu0306@users.noreply.github.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CsgeivZCqduTQmWK55zqiT
@greptile-apps

greptile-apps Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR resets frame state whenever the selected Tauri window changes and rejects delayed frame mutations after the original top-level browsing context changes or disappears.

  • Adds an atomic session-level window switch that clears the frame stack and advances a browsing-context generation.
  • Validates frame commits against the captured generation and original window lifetime.
  • Adds focused unit coverage for successful and rejected frame-context mutations.
  • Refreshes the Tauri fixture’s local package versions in Cargo.lock.

Confidence Score: 5/5

The PR appears safe to merge; the changed window-switch path consistently resets frame state and prevents delayed operations from committing into a different top-level browsing context.

The session mutation updates the window, frame stack, and generation together, while delayed frame commits verify both the captured generation and original window before changing session state.

Important Files Changed

Filename Overview
packages/tauri-plugin-webdriver/src/server/handlers/frame.rs Adds generation- and window-lifetime-checked frame commits around asynchronous frame operations, with unit coverage for each mutation.
packages/tauri-plugin-webdriver/src/webdriver/session.rs Centralizes window switching so the selected window, cleared frame stack, and browsing-context generation update together.
packages/tauri-plugin-webdriver/src/server/handlers/window.rs Routes successful window switches through the new atomic session operation and maps the theoretical generation overflow.
packages/tauri-plugin-webdriver/src/server/mod.rs Adds a window-registry predicate used to reject delayed frame commits after their original window closes.
fixtures/e2e-apps/tauri/Cargo.lock Synchronizes the two local Tauri WDIO package versions with their manifests without changing third-party dependency versions.

Sequence Diagram

sequenceDiagram
  participant Client
  participant FrameHandler
  participant Session
  participant WindowHandler

  Client->>FrameHandler: switchToFrame request
  FrameHandler->>Session: Snapshot window, frame stack, generation
  FrameHandler->>FrameHandler: Validate frame asynchronously
  Client->>WindowHandler: switchToWindow
  WindowHandler->>Session: Set window, clear frames, increment generation
  FrameHandler->>Session: Commit using captured generation
  Session-->>FrameHandler: Reject changed browsing context
Loading

Reviews (1): Last reviewed commit: "fix(tauri): reset the frame context when..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Standing release PR: #456 · 15 packages queued · open 39d 1h 47m · ✅ ready to merge

Release Preview — 17 packages

Note: Labels on this PR are advisory in standing-pr mode. Bumps come from conventional commits in the standing PR; override by editing labels on the standing PR itself. Add release:immediate to bypass the standing PR and release this PR directly.

These changes will be added to the release PR (#456) when merged:

Changelog

@wdio/dioxus-bridge 1.0.0-next.3 → 1.0.0-next.4

Changed

  • Update version to 1.0.0-next.4
@wdio/dioxus-service 1.0.0-next.3 → 1.0.0-next.4

Changed

  • Update version to 1.0.0-next.4
wdio-dioxus-driver 1.0.0-next.3 → 1.0.0-next.4

Changed

  • Update version to 1.0.0-next.4
wdio-dioxus-embedded-driver 1.0.0-next.3 → 1.0.0-next.4

Changed

  • Update version to 1.0.0-next.4
@wdio/tauri-plugin 1.2.0 → 1.2.1

Changed

  • Update version to 1.2.1
@wdio/tauri-service 1.2.0 → 1.2.1

Changed

  • Update version to 1.2.1
tauri-plugin-wdio-webdriver 1.2.0 → 1.2.1

Fixed

  • reset the frame context when switching windows (tauri)
@wdio/flutter-service 1.0.0-next.1 → 1.0.0-next.2

Changed

  • Update version to 1.0.0-next.2
wdio_flutter N/A → 0.1.1

Changed

  • Update version to 0.1.1
@wdio/electrobun-service 0.1.0 → 0.1.1

Changed

  • Update version to 0.1.1
@wdio/electron-service 10.1.0 → 10.1.1

Changed

  • Update version to 10.1.1
@wdio/native-cdp-bridge 1.0.0 → 1.0.1

Changed

  • Update version to 1.0.1
@wdio/native-core 1.0.0 → 1.0.1

Changed

  • Update version to 1.0.1
@wdio/native-mobile-core 1.0.0 → 1.0.1

Changed

  • Update version to 1.0.1
@wdio/native-spy 1.1.0 → 1.1.1

Changed

  • Update version to 1.1.1
@wdio/native-types 2.4.0 → 2.4.1

Changed

  • Update version to 2.4.1
@wdio/native-utils 2.5.0 → 2.5.1

Changed

  • Update version to 2.5.1
@wdio/react-native-service 1.0.0-next.0 → 1.0.0-next.1

Changed

  • Update version to 1.0.0-next.1

After merge — predicted release

No version escalation — this PR's changes will be included in the queued release without affecting the projected versions.

Package Standing PR This PR After merge
@wdio/dioxus-bridge 1.0.0-next.4 1.0.0-next.4 1.0.0-next.4
@wdio/dioxus-service 1.0.0-next.4 1.0.0-next.4 1.0.0-next.4
@wdio/electrobun-service 0.2.0 0.1.1 0.2.0
@wdio/electron-service 10.2.0 10.1.1 10.2.0
@wdio/native-cdp-bridge 1.1.0 1.0.1 1.1.0
@wdio/native-core 1.1.0 1.0.1 1.1.0
@wdio/native-spy 1.2.0 1.1.1 1.2.0
@wdio/native-types 2.5.0 2.4.1 2.5.0
@wdio/native-utils 2.6.0 2.5.1 2.6.0
@wdio/tauri-plugin 1.3.0 1.2.1 1.3.0
@wdio/tauri-service 1.3.0 1.2.1 1.3.0
tauri-plugin-wdio-webdriver 1.3.0 1.2.1 1.3.0
wdio_flutter 0.2.0 0.1.1 0.2.0
wdio-dioxus-driver 1.0.0-next.4 1.0.0-next.4 1.0.0-next.4
wdio-dioxus-embedded-driver 1.0.0-next.4 1.0.0-next.4 1.0.0-next.4

Updated automatically by ReleaseKit

goosewobbler added a commit that referenced this pull request Aug 1, 2026
Two more #540 DirectEval idle-stalls (`Error: Script execution timed out`,
embedded provider, WebKit macOS):
- #560 run 30701420535 — Package - Tauri [macOS-ARM]
- #559 run 30701283449 — E2E - Tauri [macOS-ARM] - deeplink (also the
  app-unreachable variant: `failed to send request … "window" GET`)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CKc4JHZKXfyqCiiU4C2b7V
goosewobbler added a commit that referenced this pull request Aug 1, 2026
More #540 DirectEval idle-stalls (`Script execution timed out` / app-unreachable
`failed to send request … "window" GET`, embedded provider, WebKit macOS):
- #560 run 30701420535 — Package - Tauri [macOS-ARM]
- #559 run 30701283449 — E2E - Tauri [macOS-ARM] - deeplink; both attempt 1 and
  the attempt-2 retry failed F1 (retry did not clear it).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CKc4JHZKXfyqCiiU4C2b7V
goosewobbler added a commit that referenced this pull request Aug 1, 2026
…acOS)

More #540 DirectEval idle-stalls (`Script execution timed out` / app-unreachable
`failed to send request … "window" GET`, embedded provider, WebKit macOS):
- #560 run 30701420535 — Package - Tauri [macOS-ARM]
- #559 run 30701283449 — E2E - Tauri [macOS-ARM] - deeplink failed F1 on all
  THREE attempts; retry never cleared it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CKc4JHZKXfyqCiiU4C2b7V
@goosewobbler
goosewobbler merged commit 59d8ace into main Aug 1, 2026
333 of 339 checks passed
@goosewobbler
goosewobbler deleted the fix/frame-context-window-switch branch August 1, 2026 22:52
@github-actions github-actions Bot mentioned this pull request Aug 1, 2026
2 tasks
goosewobbler added a commit that referenced this pull request Aug 1, 2026
…acOS)

More #540 DirectEval idle-stalls (`Script execution timed out` / app-unreachable
`failed to send request … "window" GET`, embedded provider, WebKit macOS):
- #560 run 30701420535 — Package - Tauri [macOS-ARM]
- #559 run 30701283449 — E2E - Tauri [macOS-ARM] - deeplink failed F1 on all
  THREE attempts; retry never cleared it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CKc4JHZKXfyqCiiU4C2b7V
goosewobbler added a commit that referenced this pull request Aug 1, 2026
…#540) (#563)

More #540 DirectEval idle-stalls (`Script execution timed out` / app-unreachable
`failed to send request … "window" GET`, embedded provider, WebKit macOS):
- #560 run 30701420535 — Package - Tauri [macOS-ARM]
- #559 run 30701283449 — E2E - Tauri [macOS-ARM] - deeplink failed F1 on all
  THREE attempts; retry never cleared it.


Claude-Session: https://claude.ai/code/session_01CKc4JHZKXfyqCiiU4C2b7V

Co-authored-by: Claude Opus 4.8 (1M context) <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