webext-messenger 0.15.0 → 0.15.1-0
Sign up to get free protection for your applications and to get access to all the features.
- package/distribution/receiver.js +7 -5
- package/package.json +1 -1
package/distribution/receiver.js
CHANGED
@@ -28,20 +28,22 @@ function onMessageListener(message, sender) {
|
|
28
28
|
async function handleMessage(message, sender,
|
29
29
|
// Once messages reach this function they cannot be "ignored", they're already being handled
|
30
30
|
action) {
|
31
|
-
const { type, target, args, options
|
32
|
-
|
31
|
+
const { type, target, args, options = {} } = message;
|
32
|
+
const { trace = [] } = options;
|
33
|
+
trace.push(sender);
|
34
|
+
const meta = { trace };
|
35
|
+
debug(type, "↘️ received", { sender, args, wasForwarded: trace.length > 1 });
|
33
36
|
let handleMessage;
|
34
37
|
if (action === "forward") {
|
35
38
|
debug(type, "🔀 forwarded", { sender, target });
|
36
|
-
handleMessage = async () => messenger(type,
|
39
|
+
handleMessage = async () => messenger(type, meta, target, ...args);
|
37
40
|
}
|
38
41
|
else {
|
39
42
|
const localHandler = handlers.get(type);
|
40
43
|
if (!localHandler) {
|
41
44
|
throw new MessengerError(`No handler registered for ${type} in ${getContextName()}`);
|
42
45
|
}
|
43
|
-
debug(type, "➡️ will be handled here");
|
44
|
-
const meta = { trace: [sender] };
|
46
|
+
debug(type, "➡️ will be handled here,", getContextName());
|
45
47
|
handleMessage = async () => localHandler.apply(meta, args);
|
46
48
|
}
|
47
49
|
const response = await handleMessage().then((value) => ({ value }), (error) => ({
|