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: avoid macOS auth popup crash
Tw930419e982df19
diff --git a/src-tauri/src/inject/event.js b/src-tauri/src/inject/event.jsindex 7e327e70..163ebd38 100644--- a/src-tauri/src/inject/event.js+++ b/src-tauri/src/inject/event.js@@ -272,6 +272,33 @@ function shouldBypassPakeLinkHandling(rawHref) {);}+function shouldNavigateAuthInCurrentWindow() {+ return /macintosh|mac os x/i.test(navigator.userAgent);+}++function canNavigateAuthUrl(url) {+ const normalizedUrl = normalizeAnchorHref(url).toLowerCase();+ return normalizedUrl !== "" && normalizedUrl !== "about:blank";+}++function navigateInCurrentWindow(url) {+ window.location.href = url;+ return window;+}++function openAuthNavigation(originalWindowOpen, url, name, specs) {+ if (shouldNavigateAuthInCurrentWindow() && canNavigateAuthUrl(url)) {+ return navigateInCurrentWindow(url);+ }++ const authWindow = originalWindowOpen.call(window, url, name, specs);+ if (!authWindow) {+ return navigateInCurrentWindow(url);+ }++ return authWindow;+}+document.addEventListener("DOMContentLoaded", () => {const tauri = window.__TAURI__;const appWindow = tauri.window.getCurrentWindow();@@ -440,16 +467,12 @@ document.addEventListener("DOMContentLoaded", () => {e.preventDefault();e.stopImmediatePropagation();- const authWindow = originalWindowOpen.call(- window,+ openAuthNavigation(+ originalWindowOpen,absoluteUrl,"_blank","width=1200,height=800,scrollbars=yes,resizable=yes",);-- if (!authWindow) {- window.location.href = absoluteUrl;- }}return;@@ -544,9 +567,15 @@ document.addEventListener("DOMContentLoaded", () => {return originalWindowOpen.call(window, url, name, specs);}- // Allow authentication popups to open normally+ // Avoid macOS WebKit auth-popup crashes by navigating auth URLs in-place.if (window.isAuthPopup(url, name)) {- return originalWindowOpen.call(window, url, name, specs);+ try {+ const baseUrl = window.location.origin + window.location.pathname;+ const absoluteUrl = new URL(url, baseUrl).href;+ return openAuthNavigation(originalWindowOpen, absoluteUrl, name, specs);+ } catch (error) {+ return openAuthNavigation(originalWindowOpen, url, name, specs);+ }}try {diff --git a/tests/unit/event-link-guard.test.js b/tests/unit/event-link-guard.test.jsindex 2172907a..6f2c2d0a 100644--- a/tests/unit/event-link-guard.test.js+++ b/tests/unit/event-link-guard.test.js@@ -3,7 +3,10 @@ import path from "path";import { runInNewContext } from "node:vm";import { describe, expect, it } from "vitest";-function loadEventHelpers({ withTauri = false } = {}) {+function loadEventHelpers({+ withTauri = false,+ userAgent = "Mozilla/5.0",+} = {}) {const source = fs.readFileSync(path.join(process.cwd(), "src-tauri/src/inject/event.js"),"utf-8",@@ -24,7 +27,7 @@ function loadEventHelpers({ withTauri = false } = {}) {clearTimeout,scrollTo: () => {},navigator: {- userAgent: "Mozilla/5.0",+ userAgent,language: "en-US",},window: {@@ -35,6 +38,7 @@ function loadEventHelpers({ withTauri = false } = {}) {location: {href: "https://example.com/app",origin: "https://example.com",+ pathname: "/app",reload: () => {},},localStorage: {@@ -84,6 +88,57 @@ describe("event link guard", () => {);});+ it("navigates macOS auth URLs in the current window", () => {+ const { openAuthNavigation, window } = loadEventHelpers({+ userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 15_5)",+ });+ const openCalls = [];+ const originalWindowOpen = (url, name, specs) => {+ openCalls.push({ url, name, specs });+ return {};+ };++ const result = openAuthNavigation(+ originalWindowOpen,+ "https://www.linkedin.com/login",+ "_blank",+ "width=1200,height=800",+ );++ expect(openCalls).toEqual([]);+ expect(window.location.href).toBe("https://www.linkedin.com/login");+ expect(result).toBe(window);+ });++ it("keeps blank macOS auth popups on the native popup path", () => {+ const popup = {};+ const { openAuthNavigation, window } = loadEventHelpers({+ userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 15_5)",+ });+ const openCalls = [];+ const originalWindowOpen = (url, name, specs) => {+ openCalls.push({ url, name, specs });+ return popup;+ };++ const result = openAuthNavigation(+ originalWindowOpen,+ "about:blank",+ "login",+ "width=1200,height=800",+ );++ expect(openCalls).toEqual([+ {+ url: "about:blank",+ name: "login",+ specs: "width=1200,height=800",+ },+ ]);+ expect(window.location.href).toBe("https://example.com/app");+ expect(result).toBe(popup);+ });+it("bridges Web Badging API calls to explicit badge commands", async () => {const { navigator, invokeCalls } = loadEventHelpers({ withTauri: true });