fixes #29390: align async window open behavior with inline logic

This commit is contained in:
yyh 2025-12-10 13:17:30 +08:00
parent 997ff45e56
commit de9fae63b8
No known key found for this signature in database
1 changed files with 15 additions and 11 deletions

View File

@ -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) {