Skip to content

Commit 28b9e7c

Browse files
fix: throw on custom protocol IPC fails (#14377)
1 parent 3056d44 commit 28b9e7c

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
tauri: patch:bug
3+
---
4+
5+
Fix `undefined is not an object (evaluating '[callbackId, data]')` error on custom protocol IPC fails

crates/tauri/scripts/ipc-protocol.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,21 @@
5252
return response.arrayBuffer().then((r) => [callbackId, r])
5353
}
5454
})
55-
.catch((e) => {
56-
console.warn(
57-
'IPC custom protocol failed, Tauri will now use the postMessage interface instead',
58-
e
59-
)
60-
// failed to use the custom protocol IPC (either the webview blocked a custom protocol or it was a CSP error)
61-
// so we need to fallback to the postMessage interface
62-
customProtocolIpcFailed = true
63-
sendIpcMessage(message)
64-
})
65-
.then(([callbackId, data]) => {
66-
window.__TAURI_INTERNALS__.runCallback(callbackId, data)
67-
})
55+
.then(
56+
([callbackId, data]) => {
57+
window.__TAURI_INTERNALS__.runCallback(callbackId, data)
58+
},
59+
(e) => {
60+
console.warn(
61+
'IPC custom protocol failed, Tauri will now use the postMessage interface instead',
62+
e
63+
)
64+
// failed to use the custom protocol IPC (either the webview blocked a custom protocol or it was a CSP error)
65+
// so we need to fallback to the postMessage interface
66+
customProtocolIpcFailed = true
67+
sendIpcMessage(message)
68+
}
69+
)
6870
} else {
6971
// otherwise use the postMessage interface
7072
const { data } = processIpcMessage({
@@ -78,6 +80,7 @@
7880
payload,
7981
__TAURI_INVOKE_KEY__
8082
})
83+
// `window.ipc.postMessage` came from `tauri-runtime-wry` > `wry` [`with_ipc_handler`](https://github.com/tauri-apps/wry/blob/a0403b9e2f1ff9d73be7dce1184f058afcaa1d82/src/lib.rs#L1130)
8184
window.ipc.postMessage(data)
8285
}
8386
}

0 commit comments

Comments
 (0)