From 997ff45e56cda950767c0b6752a4f79c1a113552 Mon Sep 17 00:00:00 2001 From: yyh Date: Wed, 10 Dec 2025 12:55:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20harden=20async=20window=20open=20placeho?= =?UTF-8?q?lder=20logic=EF=BC=88#29390=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/hooks/use-async-window-open.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/web/hooks/use-async-window-open.ts b/web/hooks/use-async-window-open.ts index 582ab28be4..33ccb062bd 100644 --- a/web/hooks/use-async-window-open.ts +++ b/web/hooks/use-async-window-open.ts @@ -24,21 +24,21 @@ export const useAsyncWindowOpen = () => { const newWindow = window.open('', '_blank', windowFeatures) - if (!newWindow) { - const error = new Error('Popup blocked by browser') - onError?.(error) - Toast.notify({ - type: 'error', - message: 'Popup blocked. Please allow popups for this site.', - }) - return - } - try { const url = await fetchUrl() if (url) { - newWindow.location.href = url + if (newWindow) { + try { + newWindow.opener = null + } + catch { /* noop */ } + newWindow.location.href = url + } + else { + // Fallback: navigate current tab if we couldn't get a window reference + window.location.href = url + } onSuccess?.(url) if (successMessage) { @@ -49,7 +49,7 @@ export const useAsyncWindowOpen = () => { } } else { - newWindow.close() + newWindow?.close() const error = new Error('Invalid URL received') onError?.(error) Toast.notify({ @@ -59,7 +59,7 @@ export const useAsyncWindowOpen = () => { } } catch (error) { - newWindow.close() + newWindow?.close() onError?.(error) Toast.notify({ type: 'error',