webext-messenger 0.20.0 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/distribution/index.js
CHANGED
@@ -1,8 +1,4 @@
|
|
1
|
-
// Imports must use the .js extension because
|
2
|
-
// This works in TS even if the .js doesn't exist, but it breaks Parcel (the tests builder)
|
3
|
-
// For this reason, there's an `alias` field in package.json to redirect these imports.
|
4
|
-
// If you see "@parcel/resolver-default: Cannot load file './yourNewFile.js'" you need to add it to the `alias` list
|
5
|
-
// 🥲
|
1
|
+
// Imports must use the .js extension because ESM requires it and TS refuses to rewrite .ts to .js
|
6
2
|
export * from "./receiver.js";
|
7
3
|
export * from "./sender.js";
|
8
4
|
export * from "./types.js";
|
package/distribution/receiver.js
CHANGED
@@ -43,11 +43,13 @@ action) {
|
|
43
43
|
args,
|
44
44
|
wasForwarded: trace.length > 1,
|
45
45
|
});
|
46
|
-
if (!didUserRegisterMethods()) {
|
47
|
-
throw new MessengerError(`No handlers registered in ${getContextName()}`);
|
48
|
-
}
|
49
46
|
const localHandler = handlers.get(type);
|
50
47
|
if (!localHandler) {
|
48
|
+
if (!didUserRegisterMethods()) {
|
49
|
+
// TODO: Test the handling of __getTabData in contexts that have no registered methods
|
50
|
+
// https://github.com/pixiebrix/webext-messenger/pull/82
|
51
|
+
throw new MessengerError(`No handlers registered in ${getContextName()}`);
|
52
|
+
}
|
51
53
|
throw new MessengerError(`No handler registered for ${type} in ${getContextName()}`);
|
52
54
|
}
|
53
55
|
handleMessage = async () => localHandler.apply(meta, args);
|
@@ -5,7 +5,9 @@ import { debug } from "./shared.js";
|
|
5
5
|
// Soft warning: Race conditions are possible.
|
6
6
|
// This CANNOT be awaited because waiting for it means "I will handle the message."
|
7
7
|
// If a message is received before this is ready, it will just have to be ignored.
|
8
|
-
let thisTarget
|
8
|
+
let thisTarget = isBackground()
|
9
|
+
? { page: "background" }
|
10
|
+
: undefined;
|
9
11
|
function compareTargets(to, thisTarget) {
|
10
12
|
for (const [key, value] of Object.entries(to)) {
|
11
13
|
if (thisTarget[key] === value) {
|
@@ -70,11 +72,10 @@ export function __getTabData() {
|
|
70
72
|
return { tabId: this.trace[0]?.tab?.id, frameId: this.trace[0]?.frameId };
|
71
73
|
}
|
72
74
|
export function initPrivateApi() {
|
73
|
-
if (isBackground()) {
|
74
|
-
thisTarget = { page: "background" };
|
75
|
-
}
|
76
75
|
if (isExtensionContext()) {
|
77
|
-
//
|
76
|
+
// Only `runtime` pages can handle this message but I can't remove it because its listener
|
77
|
+
// also serves the purpose of throwing a specific error when no methods have been registered.
|
78
|
+
// https://github.com/pixiebrix/webext-messenger/pull/80
|
78
79
|
registerMethods({ __getTabData });
|
79
80
|
}
|
80
81
|
}
|
package/distribution/types.d.ts
CHANGED
@@ -40,7 +40,9 @@ export declare type Message<LocalArguments extends Arguments = Arguments> = {
|
|
40
40
|
/** If the message is being sent to an intermediary receiver, also set the options */
|
41
41
|
options?: Options;
|
42
42
|
};
|
43
|
-
export declare type Sender = Runtime.MessageSender
|
43
|
+
export declare type Sender = Runtime.MessageSender & {
|
44
|
+
origin?: string;
|
45
|
+
};
|
44
46
|
export declare type MessengerMessage = Message & {
|
45
47
|
/** Guarantees that a message is meant to be handled by this library */
|
46
48
|
__webextMessenger: true;
|