summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhackademix2019-10-01 22:39:49 +0200
committerhackademix2019-10-01 22:39:49 +0200
commitcaa16365c1d61a48d23ef4401d004b492dc3ea3b (patch)
treee76c678b5575995b16057153e497f996823984a7
parente3c09d4dc014985bd90bfe6acde1a434bf65ff9b (diff)
downloadnoscript-caa16365c1d61a48d23ef4401d004b492dc3ea3b.tar.gz
noscript-caa16365c1d61a48d23ef4401d004b492dc3ea3b.tar.xz
noscript-caa16365c1d61a48d23ef4401d004b492dc3ea3b.zip
Simplified, less noisy and more resilient Messages abstraction implementation.
-rw-r--r--src/lib/Messages.js20
1 files changed, 3 insertions, 17 deletions
diff --git a/src/lib/Messages.js b/src/lib/Messages.js
index de11e66..56d6bf2 100644
--- a/src/lib/Messages.js
+++ b/src/lib/Messages.js
@@ -7,7 +7,8 @@
if (!__meta) {
// legacy message from embedder?
if (!_messageName) {
- throw new Error(`NoScript cannot handle message %s`, JSON.stringify(msg));
+ debug(`Message not in NoScript-specific format: %s`, JSON.stringify(msg));
+ return undefined;
}
__meta = {name: _messageName};
}
@@ -24,22 +25,7 @@
answers.length === 1 ? answers.pop(): Promise.all(answers)
);
}
- let context = typeof window === "object" && window.location.href || "?";
- let originalSender = __meta.originalSender || sender;
- let {url} = originalSender;
-
- if (url && context.replace(/[?#].*/, '') === url.replace(/[?#].*/, '')) {
- throw new Error(`Message ${name} ${JSON.stringify(msg)} looping to its sender (${context})`);
- }
- console.debug("Warning: no handler for message %o in context %s", msg, context);
- if (originalSender.tab && originalSender.tab.id) {
- // if we're receiving a message from content, there might be another
- // Messages instance in a different context (e.g. background page vs
- // options page vs browser action) capable of processing it, and we've
- // just "steal" it. Let's rebroadcast.
- return await Messages.send(name, msg, {originalSender});
- }
- throw new Error(`No handler registered for message "${name}" in context ${context}`);
+ debug("Warning: no handler for message %s %s in context %s", name, JSON.stringify(msg), context);
};
var Messages = {