Skip to content

armgit / Pake

Public Imported from GitHub
0

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

docs: correct what the Tauri 2.12 upgrade made false, and drop a check that could not fail

Tw93165c0d0f67b5
diff --git a/.claude/rules/tauri-runtime.md b/.claude/rules/tauri-runtime.md
index 286cccf8..cd1deac3 100644
--- a/.claude/rules/tauri-runtime.md
+++ b/.claude/rules/tauri-runtime.md
@@ -20,10 +20,10 @@ paths:
- 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 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). Never call `window.url()` directly: Wry's getter unwraps WKWebView's `URL`, which is nil for such a web view, and the panic aborts the app under `panic = "abort"`. 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.
+- 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.
-- Blank/two-stage popups need a real WindowProxy, not the main window. Normalize omitted/empty URLs to `about:blank` in both JS entry points: Tauri rejects WebKit's empty URL before calling `on_new_window`. The default native handler must create a managed blank popup with Pake's download delegate even without `--new-window`; `NewWindowResponse::Allow` does not provide that delegate. Verify actual macOS attachment bytes and preservation of the main URL, not only Chromium popup creation.
+- Blank/two-stage popups need a real WindowProxy, not the main window. Normalize omitted/empty URLs to `about:blank` in both JS entry points: Tauri through 2.10 rejected WebKit's empty URL before calling `on_new_window` (2.12 maps it to `about:blank` itself, so the JS side is now a second guard). The default native handler must create a managed blank popup with Pake's download delegate even without `--new-window`; `NewWindowResponse::Allow` does not provide that delegate. Verify actual macOS attachment bytes and preservation of the main URL, not only Chromium popup creation.
- `--download-dir` / `downloadDir` is embedded as trusted `pake.download_dir`, shared by native and IPC downloads through `get_download_dir`. Empty means system Downloads; quoted `~/path` expands against the runtime user home. Reject relative paths and absolute tilde suffixes, create missing directories on download, and surface directory creation plus file open/write failures without redirecting to another folder. Do not accept a directory from remote-page IPC arguments.
- Do not open a synchronous native save dialog inside `on_download(Requested)`. Wry (through 0.57.2) holds a `RefCell` mutable borrow across that callback; a modal panel allows another download callback to reenter and panic. A native two-download probe reproduced this with 100 ms and 500 ms spacing. The macOS completion event also omits the destination path, so URL-only bookkeeping cannot safely identify concurrent downloads of the same URL.
- WebKit subframes need `initialization_script_for_all_frames` for the lightweight config/auth/link bridge. Keep page UI and clipboard injection separate. `link_policy.js` owns internal URL matching for the main page and `frame_links.js`; the receiver must recheck descendant source, protocol, internal/auth classification, and force policy before calling the external opener. Never route frame messages through top-level internal navigation: sandboxed content can forge them. Preserve native blank/two-stage, named-frame, auth, and download behavior; known external iframe links are the repaired surface. Cover pre-DOMContentLoaded messages and discard queued messages when the document leaves.
@@ -34,7 +34,7 @@ paths:
- Linux AppImage reports often include harmless GTK, appindicator, or GStreamer warnings. Separate optional runtime warnings from the actual symptom before changing code; input/click failures on pure Wayland compositors are not the same class as blank-window failures.
- Windows taskbar icons can register blank when an autostarted app launches before Explorer's icon cache is ready (#1323). Every hidden-to-visible `window.show()` path (main or secondary: tray show/click, activation shortcut, single-instance activation, startup/page-load reveal, multi-window Cmd+N reveal) must call `reapply_window_icon` from `src-tauri/src/app/window.rs` (or go through `reveal_built_window` / `reveal_startup_window`, which already do). The helper reasserts both the small window icon and the large taskbar icon; a new show path without it regresses the bug.
- Multi-window home clones (`open_additional_window_safe`, labels `pake-N`) are built hidden and revealed via `reveal_built_window` on the first real page load (or a 3s fallback), matching the main-window blank-shell guard. OAuth/pop-up windows from `--new-window` stay immediately visible by design. Tray Hide/Show, tray left-click, and the activation shortcut must act on **every** webview via `hide_all_app_windows` / `show_all_app_windows` / `toggle_all_app_windows` (not only label `"pake"`). Two Windows-specific constraints hold that toggle together (#1343): the tray click handler must match `button_state == MouseButtonState::Up`, because Windows emits `TrayIconEvent::Click` twice per physical click and reacting to both runs the toggle twice; and `any_app_window_visible` must exclude minimized windows, because `hide_on_close` minimizes before hiding and Windows keeps `IsWindowVisible` true while a window is iconic. Locked by `tests/unit/tray-toggle-visibility.test.ts`.
-- Windows uses WebView2 native DOM fullscreen; Tauri already synchronizes its `ContainsFullScreenElementChanged` event with the native window. Do not inject `fullscreen.js` on Windows: its media extraction separates video from player controls (#1373). F11 must exit an active DOM fullscreen session through `document.exitFullscreen()` before toggling the native window. Verify the platform gate and `node --test tests/browser/fullscreen.mjs`. macOS keeps WebKit's own element fullscreen too, which Wry turns on: `fullscreen.js` returns before replacing anything when `navigator.platform` is a Mac and the engine reports `fullscreenEnabled`, and installs only where the engine has none (an old macOS). YouTube asks for fullscreen on the whole document and lays its player out by what only the engine reports, so under the polyfill the window went full screen while the video stayed a 1090x613 box at 16,68 and the button could not leave; with the engine's own the video is 1570x958 at 0,0 and the button leaves (measured on a real bundle by pressing the player's button through accessibility, 2026-11-18; a scripted `click()` carries no user gesture and cannot enter the engine's fullscreen, so drive it with `ax act`). Linux retains the polyfill, which must preserve the requested subtree even for `html`/`body` fullscreen. Never extract a video from its player controls; verify document/player entry and repeated exit with `node --test tests/browser/fullscreen.mjs`.
+- Windows uses WebView2 native DOM fullscreen; Tauri already synchronizes its `ContainsFullScreenElementChanged` event with the native window. Do not inject `fullscreen.js` on Windows: its media extraction separates video from player controls (#1373). F11 must exit an active DOM fullscreen session through `document.exitFullscreen()` before toggling the native window. Verify the platform gate and `node --test tests/browser/fullscreen.mjs`. macOS keeps WebKit's own element fullscreen too, which Wry turns on: `fullscreen.js` returns before replacing anything when `navigator.platform` is a Mac and the engine reports `fullscreenEnabled`, and installs only where the engine has none (an old macOS). YouTube asks for fullscreen on the whole document and lays its player out by what only the engine reports, so under the polyfill the window went full screen while the video stayed a 1090x613 box at 16,68 and the button could not leave; with the engine's own the video is 1570x958 at 0,0 and the button leaves (measured on a real bundle by pressing the player's button through accessibility, 2026-11-18; a scripted `click()` carries no user gesture and cannot enter the engine's fullscreen, so drive it with `ax act`). WebKit shows that fullscreen in a window of its own, so the app's window does not report full screen meanwhile: Close Window then only leaves the fullscreen and keeps the window (measured, hide-on-close on), and a second one hides it. Linux retains the polyfill, which must preserve the requested subtree even for `html`/`body` fullscreen. Never extract a video from its player controls; verify document/player entry and repeated exit with `node --test tests/browser/fullscreen.mjs`.
- Injected Linux/Windows shortcuts (Ctrl+R / [ / ]) call the `webview_navigate` IPC so reload and history use the platform webview API on blank error pages; do not route those shortcuts only through page `history` / `location`.
- 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`.
diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rs
index 1d4ace37..d2929cf2 100644
--- a/src-tauri/src/app/window.rs
+++ b/src-tauri/src/app/window.rs
@@ -1369,9 +1369,11 @@ fn web_target(url: &WebviewUrl) -> Option<Url> {
/// The address a window is showing, or `None` when it shows none. On macOS a
/// WKWebView whose web content process has died has no URL, and Wry's getter
-/// unwraps it: `window.url()` there is a panic, which the release profile
-/// turns into the app aborting (a user quit an app whose page had gone white
-/// and got a crash report, 2026-11-18). So the web view is asked first.
+/// unwrapped it through 0.54.2: `window.url()` there was a panic, which the
+/// release profile turned into the app aborting (a user quit an app whose page
+/// had gone white and got a crash report, 2026-11-18). Wry 0.57 returns an
+/// error instead; the web view is still asked first, so this stays the one
+/// reader whatever Wry does.
pub fn page_url(window: &WebviewWindow) -> Option<Url> {
#[cfg(target_os = "macos")]
{
diff --git a/src-tauri/src/inject/fullscreen.js b/src-tauri/src/inject/fullscreen.js
index ad080547..7147fedb 100644
--- a/src-tauri/src/inject/fullscreen.js
+++ b/src-tauri/src/inject/fullscreen.js
@@ -1,5 +1,6 @@
-// Polyfill for HTML5 Fullscreen API where the webview has none of its own
-// (Linux, and a macOS too old for WebKit's).
+// Polyfill for HTML5 Fullscreen API where the webview has none of its own:
+// Linux, and a Mac only if its engine reports none (Wry turns WebKit's on for
+// every macOS it supports).
// Bridges the standard requestFullscreen / exitFullscreen DOM API to Tauri's
// native window fullscreen so a player's own button works.
//
diff --git a/tests/browser/fullscreen.mjs b/tests/browser/fullscreen.mjs
index 9dcc129c..aadae1d5 100644
--- a/tests/browser/fullscreen.mjs
+++ b/tests/browser/fullscreen.mjs
@@ -92,7 +92,7 @@ test("native fullscreen preserves the player subtree and F11 exits its top layer
}
});
-// The Linux/macOS polyfill must keep video and controls in the same subtree,
+// The polyfill (Linux) must keep video and controls in the same subtree,
// including sites that request fullscreen on the document instead of the player.
for (const target of ["html", "body", "#player"]) {
test(`polyfill preserves player controls when ${target} requests fullscreen`, async () => {
diff --git a/tests/integration/ipc-security.mjs b/tests/integration/ipc-security.mjs
index f1098906..2ce69270 100644
--- a/tests/integration/ipc-security.mjs
+++ b/tests/integration/ipc-security.mjs
@@ -69,7 +69,6 @@ function page(stage, origin) {
// for a user gesture as a browser does; tests/browser/fullscreen.mjs holds
// the polyfill to leaving the player alone when this is denied.
results.fullscreen = await check("plugin:window|set_fullscreen", {label: "pake", value: true});
- results.windowStayed = innerWidth < screen.width;
`
: ""
}
@@ -247,11 +246,6 @@ try {
);
}
assert.match(untrusted.fullscreen, /^denied: .*not allowed/i);
- assert.equal(
- untrusted.windowStayed,
- true,
- "an untrusted origin made the window full screen",
- );
assert.equal(
await fs.readFile(path.join(downloads, "entry.txt"), "utf8"),
"pake-native-ipc-proof",