fix: throw on custom protocol IPC fails (#14377)

This commit is contained in:
Tony 2025-10-28 18:07:50 +08:00 committed by GitHub
parent 3056d44d96
commit 28b9e7c7b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 13 deletions

View File

@ -0,0 +1,5 @@
---
tauri: patch:bug
---
Fix `undefined is not an object (evaluating '[callbackId, data]')` error on custom protocol IPC fails

View File

@ -52,19 +52,21 @@
return response.arrayBuffer().then((r) => [callbackId, r])
}
})
.catch((e) => {
console.warn(
'IPC custom protocol failed, Tauri will now use the postMessage interface instead',
e
)
// failed to use the custom protocol IPC (either the webview blocked a custom protocol or it was a CSP error)
// so we need to fallback to the postMessage interface
customProtocolIpcFailed = true
sendIpcMessage(message)
})
.then(([callbackId, data]) => {
window.__TAURI_INTERNALS__.runCallback(callbackId, data)
})
.then(
([callbackId, data]) => {
window.__TAURI_INTERNALS__.runCallback(callbackId, data)
},
(e) => {
console.warn(
'IPC custom protocol failed, Tauri will now use the postMessage interface instead',
e
)
// failed to use the custom protocol IPC (either the webview blocked a custom protocol or it was a CSP error)
// so we need to fallback to the postMessage interface
customProtocolIpcFailed = true
sendIpcMessage(message)
}
)
} else {
// otherwise use the postMessage interface
const { data } = processIpcMessage({
@ -78,6 +80,7 @@
payload,
__TAURI_INVOKE_KEY__
})
// `window.ipc.postMessage` came from `tauri-runtime-wry` > `wry` [`with_ipc_handler`](https://github.com/tauri-apps/wry/blob/a0403b9e2f1ff9d73be7dce1184f058afcaa1d82/src/lib.rs#L1130)
window.ipc.postMessage(data)
}
}