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: build releases that unwind, so WebKit's exception cannot end the app
Tw9325f3d010636d
diff --git a/.claude/rules/tauri-runtime.md b/.claude/rules/tauri-runtime.mdindex cd1deac3..a0416015 100644--- a/.claude/rules/tauri-runtime.md+++ b/.claude/rules/tauri-runtime.md@@ -19,7 +19,7 @@ paths:- `--new-window` and `--multi-window` do not bypass every provider policy. Google OAuth and similar embedded-WebView restrictions may still require a normal browser or native client.- macOS Basic Auth keeps only an enablement boolean in CLI/config. Usernames and passwords are runtime-only input for the target host and session; never put them in CLI arguments, config, generated artifacts, logs, or persistence. Native dialog changes need a real macOS smoke covering the icon, button alignment, label/input baselines, field width, and outer margins; compile and unit tests do not prove the layout.- A sized `window.open` to a sign-in URL, or to the app's own site, is a popup flow: the popup signs in, answers `window.opener` and closes itself (the Google button on TikTok and X, Notion's own redirect page, Sign in with Apple). On macOS and Windows it gets a real window under every `--new-window` setting. Navigating the opener there instead, which macOS did from 0419e982 to avoid a WebKit abort that 63863b7e's target-configuration popups later removed, left the callback page with nobody to answer: a blank window after the Google password (user reports, 2026-11-18), and a frame's popup (Google's button on X is a frame) was refused outright. `requestsPopupWindow` in `link_policy.js` decides, and `event.js` and `frame_links.js` hand such a popup to the native `window.open` at its own address; `builds_requested_popup` in `window.rs` builds any popup that asks for a size, with or without `--new-window`. The popup must start at its address, and only the engine may load it. 41e1a6f9 opened it blank and sent it there afterwards, and on a site that sets `Cross-Origin-Opener-Policy: same-origin-allow-popups` (x.com does) WebKit keeps a popup with its opener only across the popup's first navigation, so after the Google password the popup had no opener, stayed blank and could not close (the maintainer on X, 2026-11-18, while Notion, which sends no such header, signed in). The second half is `popup_build_url`: WKWebView and WebView2 load a popup's address themselves into the web view they are handed, and Tauri, given the same address, has Wry load it again as the app's own navigation, which moves the page to another process and drops `window.opener` (measured on macOS 26.7 with the fixture: a popup opened at its address reported `opener=no`), so a popup's web view is built with `about:blank`, the one address Tauri does not load. Since the native handler builds every sized popup, a frame's sized named popup to another site takes the external route in `frame_links.js` instead of reaching it. "Sized" follows the window features as a browser reads them: commas or spaces separate, an explicit `popup` decides, `noopener` and `noreferrer` rule a popup out, since it could not be sent to its address. Every other sign-in `window.open` keeps its route through `openAuthNavigation` (no size, `noopener`, a `_self` target, a popup the engine refused): the current window on macOS and Linux, a native popup first on Windows. A sized popup of another site goes to the system browser unless its URL or its window name (`login`, `oauth` and the rest of `isAuthPopup`) marks a sign-in. WebView2 runs `event.js` in subframes too, where the app's own site is `pakeConfig.url`, not the frame's address. Linux is left out by `opensSignInPopups` until a self-closing popup has been run on a real WebKitGTK desktop: Wry destroys the web view at once there, which nobody has measured against an IPC call in flight. URL matching lives in `src-tauri/src/inject/auth.js` (`matchesAuthUrl`), covered by `tests/unit/auth-sso-patterns.test.js`; routing changes need `tests/unit/event-link-guard.test.js`, `tests/unit/frame-links.test.js` and `tests/browser/popup-routing.mjs`, whose frame cases pass on any code because Chromium never refuses a popup.-- A popup's page closes it with `window.close()`. WKWebView closes nothing for that call unless its UI delegate implements `webViewDidClose:`, which Wry's does not; `src-tauri/src/app/popup_close.rs` closes the window, and only for windows a page opened (`page_popup`), since WebKit sends the same message for a main window whose page calls `window.close()`. WebView2 raises `WindowCloseRequested`, which Wry answers by destroying only the web view's container, so the Windows arm in `build_window` closes the window too (measured in a Windows 11 VM: the popup had answered its opener and stayed on screen titled `callback`). On Linux the window stays with its web view destroyed, as before. On macOS the timing is load-bearing twice. WebKit cancels a closing page's requests, a callback page closes in its first script, and Tauri's notification plugin has an IPC call out in every document (`is_permission_granted`); the answer to a cancelled `ipc://` request makes WebKit raise, and under the release profile's `panic = "abort"` Wry's `objc2::exception::catch` cannot hold, so the whole app quit on every sign-in (measured on macOS 26.7; with `panic = "unwind"` the same run passed, at 2.0 MB more per architecture, 11.8 to 13.8 MB). So `event.js` delays every top-level page's own `window.close()` by `WINDOW_CLOSE_DELAY_MS` (every page, because a `noopener` popup has no `window.opener` to tell it by; in the main window it is a precaution, since a self-closing first page there did not abort in three runs without it), and the native side hides the window at once and destroys it after `CLOSE_GRACE`, because destroying the web view cancels requests too. Not covered: an opener that closes a cross-origin popup calls the engine's own `close`, a page that navigates within the delay after `close()` loses the close, and the same abort is possible wherever a page with an IPC call in flight is torn down. Page-opened popups take `pake-popup-N` labels (`POPUP_WINDOW_LABEL_PREFIX`) and the window-state plugin filters them out, so a popup opens at the size its page asked for and a Cmd+N window never inherits one. Verify on a real bundle with `tests/integration/signin-popup-server.mjs`, whose app pages send that opener policy: each of its three buttons must end with the app's page in place, the answer received, the popup gone and the app still running, several times in a row, and its `/selfclose` page must leave the main window open.+- A popup's page closes it with `window.close()`. WKWebView closes nothing for that call unless its UI delegate implements `webViewDidClose:`, which Wry's does not; `src-tauri/src/app/popup_close.rs` closes the window, and only for windows a page opened (`page_popup`), since WebKit sends the same message for a main window whose page calls `window.close()`. WebView2 raises `WindowCloseRequested`, which Wry answers by destroying only the web view's container, so the Windows arm in `build_window` closes the window too (measured in a Windows 11 VM: the popup had answered its opener and stayed on screen titled `callback`). On Linux the window stays with its web view destroyed, as before. On macOS the timing is load-bearing twice. WebKit cancels a closing page's requests, a callback page closes in its first script, and Tauri's notification plugin has an IPC call out in every document (`is_permission_granted`); the answer to a cancelled `ipc://` request makes WebKit raise, and under the release profile's old `panic = "abort"` Wry's `objc2::exception::catch` could not hold, so the whole app quit on every sign-in (measured on macOS 26.7; with `panic = "unwind"` the same run passed, at 2.0 MB more per architecture, 11.8 to 13.8 MB). So `event.js` delays every top-level page's own `window.close()` by `WINDOW_CLOSE_DELAY_MS` (every page, because a `noopener` popup has no `window.opener` to tell it by; in the main window it is a precaution, since a self-closing first page there did not abort in three runs without it), and the native side hides the window at once and destroys it after `CLOSE_GRACE`, because destroying the web view cancels requests too. Not covered: an opener that closes a cross-origin popup calls the engine's own `close`, a page that navigates within the delay after `close()` loses the close, and the same abort is possible wherever a page with an IPC call in flight is torn down. Page-opened popups take `pake-popup-N` labels (`POPUP_WINDOW_LABEL_PREFIX`) and the window-state plugin filters them out, so a popup opens at the size its page asked for and a Cmd+N window never inherits one. Verify on a real bundle with `tests/integration/signin-popup-server.mjs`, whose app pages send that opener policy: each of its three buttons must end with the app's page in place, the answer received, the popup gone and the app still running, several times in a row, and its `/selfclose` page must leave the main window open.- A WKWebView whose web content process dies goes white and stays white, with no URL. `recovery.rs` reloads it from Tauri's `on_web_content_process_terminate` hook, set in `lib.rs`, at most `MAX_RELOADS` times in `RELOAD_WINDOW` as on Windows and Linux. The hook must stay set: without one Tauri 2.12 reloads every time with no limit, and when Pake still replaced Wry's delegate method and called the original first (the route under Tauri 2.10, which passed no handler down), the upgrade made the third death in a minute reload as well (measured on a real bundle, 2026-11-18). Read a window's address only through `page_url`: Wry's getter unwrapped WKWebView's `URL` through 0.54.2, which is nil for such a web view, and the panic aborted the app under `panic = "abort"`; Wry 0.57 returns an error instead, and `page_url` stays the one reader, asking the web view first. A user's X app went white and then crashed on Cmd+Q, in `save_last_url` on `RunEvent::Exit` (2026-11-18); `page_url` in `window.rs` asks the web view first and is the only reader. Verify on a real bundle by killing the app's own `com.apple.WebKit.WebContent` process (the one that appears after launch): the page comes back twice, the third time it stays white, and quitting then leaves no crash report.- Auth routing matches provider hostnames and endpoint-shaped paths separately, never query strings or fragments. Tracking links carrying a login URL must still open externally. Cover main-page and subframe clicks in `tests/browser/popup-routing.mjs`; classifier-only tests do not prove routing.- tauri-plugin-shell and tauri-plugin-opener each ship a click listener of their own in every page: shell's, on `body`, opens any `a[target="_blank"]` with an http(s) address in the system browser and never asks whether the page prevented the click; opener's, on `window`, does ask. So an internal `target="_blank"` link must not still read `_blank` when the click bubbles. `detectAnchorElementClick` retargets it to `_self` under every setting; with `--new-window` it puts `_blank` back after the click and `openUnhandledBlankLink`, last in the bubble on `window`, opens the in-app window only when nobody prevented the click. Left as `_blank` under `--new-window`, a link the page handled itself went to the browser as well (Douyin's episode list, whose links carry `href="undefined"`: every switch opened douyin.com/undefined, a user's report, 2026-11-18), and a plain internal new-tab link opened in the browser instead of the app. `tests/browser/popup-routing.mjs` models the shell listener; verify on a real bundle that a handled link opens nothing and an unhandled one opens a second window, with no request from a browser at the fixture server.@@ -39,3 +39,4 @@ paths:- Download and toast paths must not hardcode `get_webview_window("pake")` when the action originates from a secondary window: IPC commands take the calling `WebviewWindow`, and `on_download` resolves toast by the event webview's label. Authenticated downloads should attach webview session cookies when available. Link-download heuristics prefer real file extensions, the `download` attribute, and `?download` / `?attachment` query hints; Cmd/Ctrl+click is navigation, not "save as"; do not re-add broad SPA roots such as `/assets/`, `/dist/`, `/files/`, or `/releases/` (see #1337, #1339).- The shared download HTTP client pools connections without a cookie jar. Redirects must re-read the calling window's cookies for each HTTP(S) target, progressively narrow Referer, and never restore it after an HTTPS downgrade. Accept page context only from the calling window's actual origin, strip URL credentials, and flush asynchronous file writes before reporting success. Wry (through 0.57.2) misses macOS literal-IP cookies; only that branch reads the window's full cookie store, with exact IP, Path, Secure and expiry filtering. Keep normal hostnames and other platforms on `cookies_for_url`. Validate the real WebView's User-Agent, Referer, HttpOnly session cookie and wrong-Path exclusion in `tests/integration/ipc-security.mjs`.- macOS menu navigation must keep working on blank error pages: Reload uses native `WebviewWindow::reload`, Go Home uses `navigate` + `resolve_home_url`, Back/Forward use the platform WKWebView history API rather than page `eval`. Copy URL reads `window.url()` so it does not depend on a live JS document.+- The release profile is `panic = "unwind"` (2026-11-19), not `abort`: under abort an Objective-C exception that crosses a Rust frame ends the app, since Wry's `objc2::exception::catch` cannot hold, and WebKit raises one whenever an `ipc://` answer arrives for a request a closing or leaving page had out. Measured on macOS 26.7 with both mitigations off (no `deferWindowClose`, `CLOSE_GRACE` 0): the abort build died on the first sign-in popup with a crash report, the unwind build finished all three flows of `tests/integration/signin-popup-server.mjs` and stayed up. It costs about 1.9 MB per architecture (12.8 to 14.7 MB on arm64). Do not switch it back for size; `tests/unit/popup-close.test.ts` holds it. The close delay and the grace stay: they let the popup's last calls finish, which unwinding does not.diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.tomlindex 868059c2..ba455f2f 100644--- a/src-tauri/Cargo.toml+++ b/src-tauri/Cargo.toml@@ -114,7 +114,12 @@ default = ["custom-protocol"]custom-protocol = ["tauri/custom-protocol"][profile.release]-panic = "abort"+# Unwind, not abort: under abort Wry's objc2::exception::catch cannot hold, so+# an Objective-C exception that crosses a Rust frame ends the whole app. WebKit+# raises one when an answer arrives for a request a closing or leaving page had+# out, and a sign-in popup closing itself ended the app that way. Costs about+# 1.9 MB per architecture (12.8 to 14.7 MB on arm64 macOS, 2026-11-19).+panic = "unwind"codegen-units = 1lto = "thin"opt-level = "z"diff --git a/src-tauri/src/app/popup_close.rs b/src-tauri/src/app/popup_close.rsindex ede093b2..60301d61 100644--- a/src-tauri/src/app/popup_close.rs+++ b/src-tauri/src/app/popup_close.rs@@ -13,10 +13,12 @@//! The window is hidden at once and closed a moment later. A callback page//! closes itself while it is still loading, when Pake's own scripts have IPC//! calls in flight; destroying the web view stops those requests, WebKit-//! raises on an answer to a stopped request, and the release profile's-//! `panic = "abort"` turns that exception into the whole app quitting (Wry's-//! `objc2::exception::catch` around the answer cannot hold under it). Measured-//! on macOS 26.7: closing at once aborted the app on every sign-in.+//! raises on an answer to a stopped request, and under the release profile's+//! old `panic = "abort"` that exception was the whole app quitting (Wry's+//! `objc2::exception::catch` around the answer could not hold under it).+//! Measured on macOS 26.7: closing at once aborted the app on every sign-in.+//! The profile unwinds since 2026-11-19, which holds the exception by itself;+//! the wait stays, so the popup's last calls still get their answers.use objc2::ffi::class_addMethod;use objc2::msg_send;diff --git a/tests/unit/popup-close.test.ts b/tests/unit/popup-close.test.tsindex 024419b1..1186ccd9 100644--- a/tests/unit/popup-close.test.ts+++ b/tests/unit/popup-close.test.ts@@ -36,6 +36,19 @@ describe('a popup its page closes', () => {expect(restored).toBeGreaterThan(reset);});+ it('builds releases that unwind, so an exception from WebKit cannot end the app', () => {+ // Under panic = "abort" Wry cannot catch the Objective-C exception WebKit+ // raises for an answer to a request a closing page had out, and the app+ // quit on every sign-in popup. Unwinding costs about 1.9 MB a build.+ const manifest = fs+ .readFileSync(path.join(process.cwd(), 'src-tauri', 'Cargo.toml'), 'utf8')+ .replace(/\r\n/g, '\n');+ const profile = manifest.slice(manifest.indexOf('[profile.release]'));+ const release = profile.slice(0, profile.indexOf('\n['));+ expect(release).toMatch(/^panic = "unwind"$/m);+ expect(release).not.toMatch(/^panic = "abort"$/m);+ });+it('leaves the main window and Cmd+N windows open on macOS', () => {const close = read('app/popup_close.rs');// WebKit sends webViewDidClose: for any page that calls window.close();