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: keep SPA internal target=_blank links inside the app

Frexty749b402afd30
diff --git a/src-tauri/src/inject/event.js b/src-tauri/src/inject/event.js
index e6c44a75..c9ff3a5e 100644
--- a/src-tauri/src/inject/event.js
+++ b/src-tauri/src/inject/event.js
@@ -486,13 +486,19 @@ document.addEventListener("DOMContentLoaded", () => {
if (isInternalUrl(absoluteUrl)) {
// With --new-window the Rust on_new_window handler opens an in-app
- // window; without it, deferring to the native handler sends the
- // _blank target to the system browser and strands SSO callbacks.
- // Navigate in place so internal links stay inside the webview.
+ // 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.
if (!window.pakeConfig?.new_window) {
- e.preventDefault();
- e.stopImmediatePropagation();
- window.location.href = absoluteUrl;
+ anchorElement.target = "_self";
}
return;
}
diff --git a/tests/unit/event-link-guard.test.js b/tests/unit/event-link-guard.test.js
index 4dd2ec9d..0e18b0ea 100644
--- a/tests/unit/event-link-guard.test.js
+++ b/tests/unit/event-link-guard.test.js
@@ -226,7 +226,7 @@ describe("event link guard", () => {
expect(context.window.location.href).toBe("https://mycompany.okta.com/sso");
});
- it("navigates target blank internal links in-place when new-window is disabled", () => {
+ it("retargets internal target=_blank links to _self instead of forcing a reload", () => {
const context = loadEventHelpers({ withTauri: true });
context.window.pakeConfig = {
new_window: false,
@@ -234,16 +234,34 @@ describe("event link guard", () => {
};
runDomReady(context);
- const event = makeClickEvent(
- makeAnchor("https://app.example.com/callback", "_blank"),
- );
+ const anchor = makeAnchor("https://app.example.com/callback", "_blank");
+ const event = makeClickEvent(anchor);
+ getClickGuard(context)(event);
+
+ // The link must be neutralized so the native webview never opens a system
+ // browser window, but the page's own click handler (and a normal in-app
+ // navigation) should still run -- so we do NOT preventDefault / reload.
+ expect(anchor.target).toBe("_self");
+ expect(event.preventDefault).not.toHaveBeenCalled();
+ expect(event.stopImmediatePropagation).not.toHaveBeenCalled();
+ expect(context.window.location.href).toBe("https://example.com/app");
+ });
+
+ it("still opens external target=_blank links in the system browser", () => {
+ const context = loadEventHelpers({ withTauri: true });
+ context.window.pakeConfig = { new_window: false };
+ runDomReady(context);
+
+ const anchor = makeAnchor("https://other.example.org/page", "_blank");
+ const event = makeClickEvent(anchor);
getClickGuard(context)(event);
expect(event.preventDefault).toHaveBeenCalled();
expect(event.stopImmediatePropagation).toHaveBeenCalled();
- expect(context.window.location.href).toBe(
- "https://app.example.com/callback",
- );
+ expect(context.invokeCalls).toContainEqual([
+ "plugin:shell|open",
+ { path: "https://other.example.org/page" },
+ ]);
});
it("bridges Web Badging API calls to explicit badge commands", async () => {