Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.
Rust chatgptclaudeclidesktopdesktop-appelectron-alternativegeminilinuxmacosnativefierno-electronrusttauriweb-to-desktopwebsite-to-appwebviewwindowsyoutube
fix: preserve macOS popup configuration
Tw9371dccbb533a8
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lockindex 7e29246e..dc2650cc 100644--- a/src-tauri/Cargo.lock+++ b/src-tauri/Cargo.lock@@ -2571,6 +2571,7 @@ dependencies = ["objc2","objc2-app-kit","objc2-foundation",+ "objc2-web-kit","serde","serde_json","tauri",diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.tomlindex eb4fcace..919e4406 100644--- a/src-tauri/Cargo.toml+++ b/src-tauri/Cargo.toml@@ -41,6 +41,11 @@ dispatch = "0.2"objc2 = "0.6"objc2-app-kit = { version = "0.3", features = ["NSApplication", "NSDockTile"] }objc2-foundation = { version = "0.3", features = ["NSString"] }+objc2-web-kit = { version = "0.3", default-features = false, features = [+ "std",+ "WKUserContentController",+ "WKWebViewConfiguration",+] }[target.'cfg(target_os = "linux")'.dependencies]# Used for native WebKitGTK go_back/go_forward on error pages (no page JS).diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rsindex a2e92a08..d705c757 100644--- a/src-tauri/src/app/window.rs+++ b/src-tauri/src/app/window.rs@@ -5,6 +5,10 @@ use crate::util::{};#[cfg(target_os = "macos")]use dispatch::Queue;+#[cfg(target_os = "macos")]+use objc2::MainThreadMarker;+#[cfg(target_os = "macos")]+use objc2_web_kit::WKUserContentController;#[cfg(target_os = "windows")]use std::{os::windows::ffi::OsStrExt, ptr, sync::OnceLock};use std::{@@ -28,6 +32,24 @@ use tauri::Theme;#[cfg(target_os = "macos")]use tauri::TitleBarStyle;+#[cfg(target_os = "macos")]+fn prepare_macos_new_window_configuration(features: &NewWindowFeatures) -> tauri::Result<()> {+ let mtm = MainThreadMarker::new().ok_or_else(|| {+ std::io::Error::other("macOS new-window configuration must run on the main thread")+ })?;+ // WebKit requires the exact target configuration it supplied to be used+ // for the new page. Replace only the inherited content controller so Wry+ // can register Pake's IPC handler and scripts once on the new webview.+ let controller = unsafe { WKUserContentController::new(mtm) };+ unsafe {+ features+ .opener()+ .target_configuration+ .setUserContentController(&controller);+ }+ Ok(())+}+#[cfg(target_os = "windows")]fn build_proxy_browser_arg(url: &Url) -> Option<String> {let host = url.host_str()?;@@ -594,26 +616,10 @@ fn build_window(}if let Some(features) = new_window_features {- // Reuse only opener-provided position/size on macOS; sharing the opener- // WKWebViewConfiguration triggers duplicate WKScriptMessageHandler- // registrations on macOS 26+ and crashes the app (issue #1194).#[cfg(target_os = "macos")]- {- if let Some(position) = features.position() {- window_builder = window_builder.position(position.x, position.y);- }-- if let Some(size) = features.size() {- window_builder = window_builder.inner_size(size.width, size.height);- }+ prepare_macos_new_window_configuration(&features)?;- window_builder = window_builder.focused(true);- }-- #[cfg(not(target_os = "macos"))]- {- window_builder = window_builder.window_features(features).focused(true);- }+ window_builder = window_builder.window_features(features).focused(true);}// Capture webview-initiated downloads (blob:, data:, Content-Disposition,diff --git a/tests/unit/new-window-macos.test.js b/tests/unit/new-window-macos.test.jsindex eefc6e74..7d80299e 100644--- a/tests/unit/new-window-macos.test.js+++ b/tests/unit/new-window-macos.test.js@@ -18,24 +18,27 @@ describe("macOS new-window handling (regression: #1194)", () => {const newWindowBlock = source.slice(blockStart, blockEnd);- // The fix for #1194 unifies all platforms behind open_requested_window so- // popups never reuse the opener WKWebViewConfiguration. Guard against- // accidental reintroduction of NewWindowResponse::Allow which crashes- // macOS 26 with WKUserContentController duplicate handler errors.+ // Pake must create the popup itself so Wry can install its own delegates+ // and custom protocol state. NewWindowResponse::Allow creates a plain+ // WKWebView that does not have Pake's runtime state.expect(newWindowBlock).toContain("open_requested_window");expect(newWindowBlock).toContain("NewWindowResponse::Create");expect(newWindowBlock).not.toMatch(/NewWindowResponse::Allow\b/);expect(newWindowBlock).not.toMatch(/#\[cfg\(target_os = "macos"\)\]/);});- it("does not clone the opener WKWebViewConfiguration on macOS popup features", () => {- // The popup-features handler in build_window must never call- // .with_webview_configuration(features.opener().target_configuration)- // because the cloned configuration carries the parent's- // WKScriptMessageHandler set, which WebKit refuses to register twice and- // aborts the process on macOS 26.+ it("uses WebKit's target configuration with a fresh user content controller", () => {+ // WebKit requires createNewPage to return a WKWebView built from the exact+ // target configuration. Reusing its inherited WKUserContentController,+ // however, makes Wry register the `ipc` handler twice. Reset only the+ // controller, then let Tauri consume all opener-provided window features.const source = fs.readFileSync(sourcePath, "utf-8");- expect(source).not.toContain("with_webview_configuration");- expect(source).not.toContain("target_configuration.clone()");+ expect(source).toContain(+ "prepare_macos_new_window_configuration(&features)?",+ );+ expect(source).toContain("setUserContentController(&controller)");+ expect(source).toContain("window_features(features).focused(true)");+ expect(source).not.toContain("removeAllUserScripts");+ expect(source).not.toContain("removeAllScriptMessageHandlers");});});