aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-09-04 17:59:38 -0400
committerGitHub <noreply@github.com>2020-09-04 17:59:38 -0400
commitcf35b9338f76d97d2e11e2d9b6774be3a19cc903 (patch)
tree591c7275bda6679c96837c7c5fa4f6865b7dd1d3
parent95bfe2d9016ef982cdab17b616134aaf44b9753e (diff)
Fix cross frame comm issues (#765)
* Send ack before sending error response * Fix error response not being JSON'ified * Use _sendResult
-rw-r--r--ext/mixed/js/comm.js11
1 files changed, 6 insertions, 5 deletions
diff --git a/ext/mixed/js/comm.js b/ext/mixed/js/comm.js
index 27cb0c34..10e1f93b 100644
--- a/ext/mixed/js/comm.js
+++ b/ext/mixed/js/comm.js
@@ -171,13 +171,14 @@ class CrossFrameAPIPort extends EventDispatcher {
// Invocation
_onInvoke(id, {action, params}) {
- const callback = (response) => this._sendResponse({type: 'result', id, data: response});
const messageHandler = this._messageHandlers.get(action);
+ this._sendAck(id);
if (typeof messageHandler === 'undefined') {
- callback({error: new Error(`Unknown action: ${action}`)});
+ this._sendError(id, new Error(`Unknown action: ${action}`));
return false;
}
- this._sendAck(id);
+
+ const callback = (data) => this._sendResult(id, data);
return yomichan.invokeMessageHandler(messageHandler, params, callback);
}
@@ -194,8 +195,8 @@ class CrossFrameAPIPort extends EventDispatcher {
this._sendResponse({type: 'ack', id});
}
- _sendResult(id, result) {
- this._sendResponse({type: 'result', id, data: {result}});
+ _sendResult(id, data) {
+ this._sendResponse({type: 'result', id, data});
}
_sendError(id, error) {