Skip to content

fix(macos): avoid panicking on missing webview URL#1729

Open
gilgtm wants to merge 1 commit into
tauri-apps:devfrom
gilgtm:gil/handle-nil-wkwebview-url
Open

fix(macos): avoid panicking on missing webview URL#1729
gilgtm wants to merge 1 commit into
tauri-apps:devfrom
gilgtm:gil/handle-nil-wkwebview-url

Conversation

@gilgtm
Copy link
Copy Markdown

@gilgtm gilgtm commented May 13, 2026

🤖 Sent by my AI agent on behalf of @gilgtm.

Why

On macOS and iOS, WKWebView.URL() can be nil. Wry currently unwraps that optional value in WebView::url, which can panic the host process instead of returning an error to the caller.

What

  • Return an Error::Io when WKWebView.URL() is unavailable
  • Return an Error::Io when the URL cannot produce an absolute string
  • Add a patch changeset for the Darwin WebView URL getter fix

Risk Assessment

Low — this only changes the failure path for the Darwin URL getter. The existing successful URL conversion path is unchanged.

References

Validated locally on macOS:

  • cargo fmt --check
  • cargo check
  • cargo test

Generated with Codex

@gilgtm gilgtm marked this pull request as ready for review May 13, 2026 15:29
@gilgtm gilgtm requested a review from a team as a code owner May 13, 2026 15:29
@FabianLars
Copy link
Copy Markdown
Member

On macOS and iOS, WKWebView.URL() can be nil

Do you have an example when this is the case? In all these years i don't think i've ever seen it. Of course, getting rid of unwrap is always good, just wondering.

@bennettandrews
Copy link
Copy Markdown

@FabianLars

I ran into this too I think when trying to serve content with foliate-js in my tauri app, but still digging in. It paginates by loading each chapter into a sandboxed iframe from a blob URL:

  iframe.setAttribute('sandbox', 'allow-same-origin allow-scripts')
  iframe.src = URL.createObjectURL(blob)

In a Tauri app on macOS, it triggers decidePolicyForNavigationAction for that blob: sandboxed sub-frame, and the WKNavigationAction's request URL comes back nil which panics. The same hazard at also in other spots across the WKWebView delegates.

@Legend-Master Legend-Master added platform: macOS ai-slop Low effort content, see https://github.com/tauri-apps/tauri?tab=contributing-ov-file#ai-tool-policy labels May 20, 2026
@gilgtm
Copy link
Copy Markdown
Author

gilgtm commented May 20, 2026

I have a concrete instance now, though not a minimal repro yet.

Environment:

  • macOS
  • Tauri 2.10.3
  • tauri-runtime-wry 2.10.1
  • Wry 0.54.2

The app had a visible WKWebView, but the webview was frozen/unresponsive after sustained background load. When tooling queried the Tauri window/webview state (to debug the frozen state), Tauri sent WebviewMessage::Url, which called through to Wry’s WebView::url(). At that point WKWebView.URL() returned nil and Wry panicked at the unwrap.

Relevant stack:

PANIC: panicked at wry-0.54.2/src/wkwebview/mod.rs:1304:40:
called `Option::unwrap()` on a `None` value

13: wry::wkwebview::url_from_webview
    at wry-0.54.2/src/wkwebview/mod.rs:1304:40
14: wry::wkwebview::InnerWebView::url
15: wry::WebView::url
16: tauri_runtime_wry::handle_user_message
    at tauri-runtime-wry-2.10.1/src/lib.rs:3761

@github-actions
Copy link
Copy Markdown
Contributor

Package Changes Through 17272eb

There are 1 changes which include wry with minor

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
wry 0.55.1 0.56.0

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

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

Labels

ai-slop Low effort content, see https://github.com/tauri-apps/tauri?tab=contributing-ov-file#ai-tool-policy platform: macOS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants