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: keep an internal target="_new" link in the app
Tw935a88ac0f853c
diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rsindex df233437..d6deed3b 100644--- a/src-tauri/src/app/window.rs+++ b/src-tauri/src/app/window.rs@@ -279,14 +279,19 @@ mod popup_tests {// in-app window must wait for the end of the bubble.let script = include_str!("../inject/event.js").replace("\r\n", "\n");let retarget = script- .find(- "anchorElement.target = \"_self\";\n if (window.pakeConfig?.new_window) {",- )+ .find("anchorElement.target = \"_self\";\n if (window.pakeConfig?.new_window) {").expect("the link is retargeted under every setting");let pending = script[retarget..].find("pendingBlankLink = {").expect("--new-window leaves the open to the end of the bubble");assert!(pending < 200);+ // Both new-tab targets go through it.+ assert_eq!(+ script+ .matches("keepInternalNewTabLinkInApp(e, anchorElement, absoluteUrl);")+ .count(),+ 2+ );assert!(script.contains("if (!pending || pending.event !== e || e.defaultPrevented) return;"));diff --git a/src-tauri/src/inject/event.js b/src-tauri/src/inject/event.jsindex 8e28d0f2..4bb65a04 100644--- a/src-tauri/src/inject/event.js+++ b/src-tauri/src/inject/event.js@@ -879,6 +879,39 @@ document.addEventListener("DOMContentLoaded", () => {originalWindowOpen.call(window, pending.url, "_blank");};+ // An internal link that asks for a new tab (target _blank or _new).+ //+ // With --new-window the Rust on_new_window handler opens an in-app window.+ // Without it, leaving the target untouched lets the native webview+ // escalate the click to a system-browser "new window".+ //+ // Many SPAs (e.g. Plane) tag in-app links with target="_blank" but route+ // the click themselves via a React onClick that calls preventDefault ++ // client-side navigation. Forcing a full window.location reload here (and+ // stopping propagation) would defeat that handler and reload the whole app+ // on every click. Instead, retarget the link to "_self" so the webview+ // never opens a browser window, then let the page's own handler run. If+ // nothing intercepts the click, the default _self navigation keeps it+ // inside the app.+ //+ // With --new-window the link is retargeted for this click as well: left+ // as _blank, Tauri's shell plugin, whose own click listener on body opens+ // every target="_blank" link in the system browser without asking whether+ // the page handled the click, sent the link there even after the page had+ // (Douyin's episode list: each switch opened douyin.com/undefined in the+ // browser, a user's report, 2026-11-18). openUnhandledBlankLink, last in+ // the bubble, opens the in-app window when nobody prevented the click.+ const keepInternalNewTabLinkInApp = (e, anchorElement, absoluteUrl) => {+ const askedFor = anchorElement.target;+ anchorElement.target = "_self";+ if (window.pakeConfig?.new_window) {+ pendingBlankLink = { event: e, anchor: anchorElement, url: absoluteUrl };+ setTimeout(() => {+ anchorElement.target = askedFor;+ }, 0);+ }+ };+const detectAnchorElementClick = (e) => {// Safety check: ensure e.target exists and is an Element with closest methodif (!e.target || typeof e.target.closest !== "function") {@@ -932,38 +965,7 @@ document.addEventListener("DOMContentLoaded", () => {}if (isInternalUrl(absoluteUrl)) {- // With --new-window the Rust on_new_window handler opens an in-app- // window. Without it, leaving target="_blank" untouched lets the- // native webview escalate the click to a system-browser "new window".- //- // Many SPAs (e.g. Plane) tag in-app links with target="_blank" but- // route the click themselves via a React onClick that calls- // preventDefault + client-side navigation. Forcing a full- // window.location reload here (and stopping propagation) would defeat- // that handler and reload the whole app on every click. Instead,- // retarget the link to "_self" so the webview never opens a browser- // window, then let the page's own handler run. If nothing intercepts- // the click, the default _self navigation keeps it inside the app.- //- // With --new-window the link is retargeted for this click as well:- // left as _blank, Tauri's shell plugin, whose own click listener- // on body opens every target="_blank" link in the system browser- // without asking whether the page handled the click, sent the- // link there even after the page had (Douyin's episode list:- // each switch opened douyin.com/undefined in the browser, a- // user's report, 2026-11-18). openUnhandledBlankLink, last in the- // bubble, opens the in-app window when nobody prevented the click.- anchorElement.target = "_self";- if (window.pakeConfig?.new_window) {- pendingBlankLink = {- event: e,- anchor: anchorElement,- url: absoluteUrl,- };- setTimeout(() => {- anchorElement.target = "_blank";- }, 0);- }+ keepInternalNewTabLinkInApp(e, anchorElement, absoluteUrl);return;}@@ -981,6 +983,14 @@ document.addEventListener("DOMContentLoaded", () => {return;}+ // "_new" is one more name for a new tab: a link to the app's own+ // site stays in the app as a _blank one does, instead of leaving+ // for the system browser.+ if (isInternalUrl(absoluteUrl)) {+ keepInternalNewTabLinkInApp(e, anchorElement, absoluteUrl);+ return;+ }+e.preventDefault();handleExternalLink(absoluteUrl);return;diff --git a/tests/unit/event-link-guard.test.js b/tests/unit/event-link-guard.test.jsindex 3d3a06ab..fbe70f7d 100644--- a/tests/unit/event-link-guard.test.js+++ b/tests/unit/event-link-guard.test.js@@ -1107,6 +1107,20 @@ describe("event link guard", () => {}});+ it("keeps an internal _new link in the app instead of the system browser", () => {+ const context = loadEventHelpers({ withTauri: true });+ context.window.pakeConfig = { new_window: false };+ runDomReady(context);+ const anchor = makeAnchor("https://example.com/video/1", "_new");+ const event = makeClickEvent(anchor);+ getClickGuard(context)(event);+ expect(anchor.target).toBe("_self");+ expect(event.preventDefault).not.toHaveBeenCalled();+ expect(+ context.invokeCalls.filter(([cmd]) => cmd === "plugin:shell|open"),+ ).toEqual([]);+ });+it("opens a new-window link nobody handled in an in-app window", () => {try {const { context, nativeOpen, lastInBubble } = loadNewWindowPage();