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: preserve apple auth popup flow

Tw934970f8f80987
diff --git a/docs/faq.md b/docs/faq.md
index 112d8176..342095d0 100644
--- a/docs/faq.md
+++ b/docs/faq.md
@@ -526,7 +526,7 @@ This is usually due to web compatibility issues. Try:
Some authentication providers, especially Google, may block sign-in inside embedded webviews. Because Pake packages sites into a desktop webview, Google properties or sites that rely on Google OAuth may still fail to sign in even when `--new-window` or `--multi-window` is enabled. This is provider policy, not a packaging bug. In those cases, use the normal browser, a browser-installed app, or a native desktop client.
- On macOS specifically, sites that use **Sign in with Apple** in popup mode (e.g. Yelp, Upwork) may end on a blank window after you authenticate. To avoid a WebKit crash, Pake navigates auth URLs in the current window on macOS, which breaks the popup's callback to the original page. Sign in to those sites with a normal browser or a native app.
+ On macOS, Pake keeps **Sign in with Apple** popup flows (e.g. Yelp, Upwork) on the native popup path so Apple's callback can return to the opener page. Other auth popups may still be navigated in the current window to avoid WebKit crashes. If a provider blocks embedded webviews or the login still fails, use the normal browser, a browser-installed app, or a native desktop client.
5. **WeChat Web login environment error**
diff --git a/docs/faq_CN.md b/docs/faq_CN.md
index 76775db5..95088abe 100644
--- a/docs/faq_CN.md
+++ b/docs/faq_CN.md
@@ -523,7 +523,7 @@ Pake 可以自动转换图标,但提供正确的格式更可靠。
某些认证提供方,尤其是 Google,可能会阻止在嵌入式 WebView 中完成登录。由于 Pake 是把网站包装进桌面 WebView,Google 自家站点或依赖 Google OAuth 的网站,即使启用了 `--new-window` 或 `--multi-window`,也仍然可能无法在应用内完成登录。这属于提供方策略限制,不是打包逻辑错误。遇到这种情况时,建议改用普通浏览器、浏览器安装版站点应用,或官方原生桌面客户端。
- 在 macOS 上,使用 **Sign in with Apple**(弹窗模式)的站点(例如 Yelp、Upwork)可能在认证后停在白屏。为规避 WebKit 崩溃,Pake 在 macOS 上会把认证 URL 在当前窗口内跳转,这会打断弹窗回调原页面的流程。这类站点请改用普通浏览器或原生 App 登录。
+ 在 macOS 上,Pake 会让 **Sign in with Apple**(弹窗模式,例如 Yelp、Upwork)继续走原生弹窗路径,确保 Apple 的回调可以返回原页面。其他认证弹窗仍可能在当前窗口内跳转,以规避 WebKit 崩溃。如果提供方拦截嵌入式 WebView,或登录仍然失败,建议改用普通浏览器、浏览器安装版站点应用,或官方原生桌面客户端。
5. **微信 Web 版登录环境异常**
diff --git a/src-tauri/src/inject/event.js b/src-tauri/src/inject/event.js
index d0aa565c..7fbfe9ae 100644
--- a/src-tauri/src/inject/event.js
+++ b/src-tauri/src/inject/event.js
@@ -446,12 +446,34 @@ function canNavigateAuthUrl(url) {
return normalizedUrl !== "" && normalizedUrl !== "about:blank";
}
+function isAppleAuthPopup(url, name) {
+ if (name === "AppleAuthentication") {
+ return true;
+ }
+
+ try {
+ return (
+ new URL(url, window.location.href).hostname.toLowerCase() ===
+ "appleid.apple.com"
+ );
+ } catch (error) {
+ return false;
+ }
+}
+
function navigateInCurrentWindow(url) {
window.location.href = url;
return window;
}
function openAuthNavigation(originalWindowOpen, url, name, specs) {
+ if (isAppleAuthPopup(url, name)) {
+ const authWindow = originalWindowOpen.call(window, url, name, specs);
+ if (authWindow) {
+ return authWindow;
+ }
+ }
+
if (shouldNavigateAuthInCurrentWindow() && canNavigateAuthUrl(url)) {
return navigateInCurrentWindow(url);
}
diff --git a/tests/unit/event-link-guard.test.js b/tests/unit/event-link-guard.test.js
index 0e18b0ea..fcb70d2f 100644
--- a/tests/unit/event-link-guard.test.js
+++ b/tests/unit/event-link-guard.test.js
@@ -210,6 +210,88 @@ describe("event link guard", () => {
expect(result).toBe(popup);
});
+ it("keeps named Apple auth popups on the native popup path on macOS", () => {
+ 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,
+ "https://example.com/apple/login",
+ "AppleAuthentication",
+ "width=1200,height=800",
+ );
+
+ expect(openCalls).toEqual([
+ {
+ url: "https://example.com/apple/login",
+ name: "AppleAuthentication",
+ specs: "width=1200,height=800",
+ },
+ ]);
+ expect(window.location.href).toBe("https://example.com/app");
+ expect(result).toBe(popup);
+ });
+
+ it("keeps appleid auth URL popups on the native popup path on macOS", () => {
+ 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,
+ "https://appleid.apple.com/auth/authorize",
+ "_blank",
+ "width=1200,height=800",
+ );
+
+ expect(openCalls).toEqual([
+ {
+ url: "https://appleid.apple.com/auth/authorize",
+ name: "_blank",
+ specs: "width=1200,height=800",
+ },
+ ]);
+ expect(window.location.href).toBe("https://example.com/app");
+ expect(result).toBe(popup);
+ });
+
+ it("falls back to current-window navigation if an Apple auth popup is blocked", () => {
+ const { openAuthNavigation, window } = loadEventHelpers({
+ userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 15_5)",
+ });
+ const originalWindowOpen = vi.fn(() => null);
+
+ const result = openAuthNavigation(
+ originalWindowOpen,
+ "https://appleid.apple.com/auth/authorize",
+ "_blank",
+ "width=1200,height=800",
+ );
+
+ expect(originalWindowOpen).toHaveBeenCalledWith(
+ "https://appleid.apple.com/auth/authorize",
+ "_blank",
+ "width=1200,height=800",
+ );
+ expect(window.location.href).toBe(
+ "https://appleid.apple.com/auth/authorize",
+ );
+ expect(result).toBe(window);
+ });
+
it("navigates target blank auth links in-place when new-window is disabled", () => {
const context = loadEventHelpers({ withTauri: true });
context.window.pakeConfig = { new_window: false };