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.

fix: use WebKit's own fullscreen on macOS, so YouTube's player fills the screen

Tw93cd60cc83d6af
diff --git a/.claude/rules/tauri-runtime.md b/.claude/rules/tauri-runtime.md
index a9cce76f..2559a3db 100644
--- a/.claude/rules/tauri-runtime.md
+++ b/.claude/rules/tauri-runtime.md
@@ -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/Linux retain 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`). 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 0.54.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/inject/fullscreen.js b/src-tauri/src/inject/fullscreen.js
index 84b375c7..ad080547 100644
--- a/src-tauri/src/inject/fullscreen.js
+++ b/src-tauri/src/inject/fullscreen.js
@@ -1,12 +1,27 @@
-// Polyfill for HTML5 Fullscreen API in Tauri webview.
+// Polyfill for HTML5 Fullscreen API where the webview has none of its own
+// (Linux, and a macOS too old for WebKit's).
// Bridges the standard requestFullscreen / exitFullscreen DOM API to Tauri's
-// native window fullscreen so video sites (YouTube, Vimeo, Bilibili, etc.) can
-// go true fullscreen on their player buttons.
+// native window fullscreen so a player's own button works.
//
// Split out from component.js so a future CLI flag (or custom.js override)
// can short-circuit the polyfill for apps that don't need video fullscreen.
(function () {
if (window.__PAKE_FULLSCREEN_POLYFILL__) return;
+
+ // WebKit on macOS has an element fullscreen of its own, which Wry turns on,
+ // and a player needs the real one: YouTube asks for the whole document and
+ // then lays its player out by what only the engine can report, so under the
+ // polyfill the video stayed a box in a full-screen page and the button
+ // could not leave. Read the engine's answer before anything here replaces it.
+ function engineHasFullscreen() {
+ if (!/^Mac/.test(navigator.platform || "")) return false;
+ return (
+ document.fullscreenEnabled === true ||
+ document.webkitFullscreenEnabled === true
+ );
+ }
+ if (engineHasFullscreen()) return;
+
window.__PAKE_FULLSCREEN_POLYFILL__ = true;
function initFullscreenPolyfill() {
diff --git a/tests/browser/fullscreen.mjs b/tests/browser/fullscreen.mjs
index bed0b4b5..9dcc129c 100644
--- a/tests/browser/fullscreen.mjs
+++ b/tests/browser/fullscreen.mjs
@@ -111,6 +111,8 @@ for (const target of ["html", "body", "#player"]) {
video{width:100%;height:100%}#preview{width:80px;height:45px;position:fixed;top:0;right:0}#controls{position:absolute;bottom:20px;left:20px;z-index:10}</style>
<section id="player"><video></video><button id="controls">Pause</button></section><video id="preview"></video>`);
await page.evaluate(() => {
+ // The polyfill is for Linux; on macOS the engine's own is kept.
+ Object.defineProperty(navigator, "platform", { value: "Linux x86_64" });
let fullscreen = false;
window.__PAKE_NATIVE__ = {
window: {
@@ -193,6 +195,7 @@ test("denied polyfill fullscreen leaves the player in its original layout", asyn
'<main><section id="player"><video></video><button>Pause</button></section></main>',
);
await page.evaluate(() => {
+ Object.defineProperty(navigator, "platform", { value: "Linux x86_64" });
window.__PAKE_NATIVE__ = {
window: {
getCurrentWindow: () => ({
@@ -237,3 +240,66 @@ test("denied polyfill fullscreen leaves the player in its original layout", asyn
await browser.close();
}
});
+
+test("macOS keeps the engine's own fullscreen instead of the polyfill", async () => {
+ const browser = await chromium.launch({
+ headless: true,
+ ...(process.env.PAKE_BROWSER_EXECUTABLE
+ ? { executablePath: process.env.PAKE_BROWSER_EXECUTABLE }
+ : {}),
+ });
+ try {
+ const page = await browser.newPage();
+ await page.setContent('<section id="player"><video></video></section>');
+ const result = await page.evaluate(
+ async (source) => {
+ const load = (platform) => {
+ const frame = document.createElement("iframe");
+ frame.allowFullscreen = true;
+ document.body.appendChild(frame);
+ const view = frame.contentWindow;
+ Object.defineProperty(view.navigator, "platform", {
+ value: platform,
+ });
+ const native = view.Element.prototype.requestFullscreen;
+ view.__PAKE_NATIVE__ = {
+ window: { getCurrentWindow: () => ({}) },
+ };
+ view.eval(source);
+ return new Promise((resolve) =>
+ setTimeout(
+ () =>
+ resolve({
+ engineEnabled: view.document.fullscreenEnabled,
+ replaced: view.Element.prototype.requestFullscreen !== native,
+ marked: view.__PAKE_FULLSCREEN_POLYFILL__ === true,
+ }),
+ 300,
+ ),
+ );
+ };
+ return {
+ mac: await load("MacIntel"),
+ linux: await load("Linux x86_64"),
+ };
+ },
+ await fs.readFile(
+ `${process.env.PAKE_INJECT_ROOT || "src-tauri/src/inject"}/fullscreen.js`,
+ "utf8",
+ ),
+ );
+ // YouTube's player only fills the screen under the engine's fullscreen.
+ assert.deepEqual(result.mac, {
+ engineEnabled: true,
+ replaced: false,
+ marked: false,
+ });
+ assert.deepEqual(result.linux, {
+ engineEnabled: true,
+ replaced: true,
+ marked: true,
+ });
+ } finally {
+ await browser.close();
+ }
+});
diff --git a/tests/integration/ipc-security.mjs b/tests/integration/ipc-security.mjs
index ff025294..f1098906 100644
--- a/tests/integration/ipc-security.mjs
+++ b/tests/integration/ipc-security.mjs
@@ -64,12 +64,12 @@ function page(stage, origin) {
anchor.remove();
await new Promise(resolve => setTimeout(resolve, 500));
}
- const player = document.querySelector("#player");
- const parent = player.parentElement;
- try { await player.requestFullscreen(); results.fullscreen = "allowed"; }
- catch (error) { results.fullscreen = "denied: " + String(error); }
- results.layoutPreserved = player.parentElement === parent
- && document.fullscreenElement === null && !document.querySelector(".pake-fullscreen-element, .pake-fullscreen-active");
+ // The polyfill's route to a full-screen window, where the engine has no
+ // fullscreen of its own. macOS uses WebKit's, which is no IPC call and asks
+ // 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;
`
: ""
}
@@ -248,9 +248,9 @@ try {
}
assert.match(untrusted.fullscreen, /^denied: .*not allowed/i);
assert.equal(
- untrusted.layoutPreserved,
+ untrusted.windowStayed,
true,
- "denied fullscreen changed the player layout",
+ "an untrusted origin made the window full screen",
);
assert.equal(
await fs.readFile(path.join(downloads, "entry.txt"), "utf8"),
@@ -267,7 +267,7 @@ try {
await assert.rejects(fs.stat(file), { code: "ENOENT" });
}
console.log(
- "Native IPC PASS: download UA, Referer and HttpOnly cookies match the webview; entry commands and window.print work, cross-origin commands are denied, browser downloads survive denied IPC, fullscreen denial preserves layout, traversal remains inside Downloads.",
+ "Native IPC PASS: download UA, Referer and HttpOnly cookies match the webview; entry commands and window.print work, cross-origin commands are denied, browser downloads survive denied IPC, an untrusted origin cannot make the window full screen, traversal remains inside Downloads.",
);
} finally {
if (app && app.exitCode === null) {