diff --git a/web/hooks/use-async-window-open.ts b/web/hooks/use-async-window-open.ts index 33ccb062bd..c767097ca3 100644 --- a/web/hooks/use-async-window-open.ts +++ b/web/hooks/use-async-window-open.ts @@ -17,28 +17,32 @@ export const useAsyncWindowOpen = () => { const { successMessage, errorMessage = 'Failed to open page', - windowFeatures = 'noopener,noreferrer', + windowFeatures = 'noopener', onError, onSuccess, } = options const newWindow = window.open('', '_blank', windowFeatures) + if (!newWindow) { + const error = new Error('Failed to open new window') + onError?.(error) + Toast.notify({ + type: 'error', + message: errorMessage, + }) + return + } + try { const url = await fetchUrl() if (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 + try { + newWindow.opener = null } + catch { /* noop */ } + newWindow.location.href = url onSuccess?.(url) if (successMessage) {