From 28b9e7c7b83845c35fe46c37e8ed8e9022b4634e Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Tue, 28 Oct 2025 18:07:50 +0800 Subject: [PATCH] fix: throw on custom protocol IPC fails (#14377) --- .changes/run-callback-after-catch.md | 5 +++++ crates/tauri/scripts/ipc-protocol.js | 29 +++++++++++++++------------- 2 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 .changes/run-callback-after-catch.md diff --git a/.changes/run-callback-after-catch.md b/.changes/run-callback-after-catch.md new file mode 100644 index 000000000..9eefa9493 --- /dev/null +++ b/.changes/run-callback-after-catch.md @@ -0,0 +1,5 @@ +--- +tauri: patch:bug +--- + +Fix `undefined is not an object (evaluating '[callbackId, data]')` error on custom protocol IPC fails diff --git a/crates/tauri/scripts/ipc-protocol.js b/crates/tauri/scripts/ipc-protocol.js index 7f8f0e29a..9ca244053 100644 --- a/crates/tauri/scripts/ipc-protocol.js +++ b/crates/tauri/scripts/ipc-protocol.js @@ -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) } }