webext-messenger 0.25.2 → 0.26.0
Sign up to get free protection for your applications and to get access to all the features.
- package/distribution/sender.js +14 -5
- package/distribution/types.d.ts +2 -2
- package/package.json +1 -1
package/distribution/sender.js
CHANGED
@@ -128,9 +128,16 @@ async function manageMessage(type, target, seq, retry, sendMessage) {
|
|
128
128
|
log.debug(type, seq, "↘️ replied successfully", response.value);
|
129
129
|
return response.value;
|
130
130
|
}
|
131
|
+
// Not a UID nor a truly global sequence. Signal / console noise compromise.
|
132
|
+
// The time part is a pseudo-random number between 0 and 99 that helps visually
|
133
|
+
// group messages from the same context. Keeping it a number also gives it a different
|
134
|
+
// color in the console log.
|
135
|
+
// Example log when seen in the background page:
|
136
|
+
// Tab 1 sends: 33000, 33001, 33002
|
137
|
+
// Tab 2 sends: 12000, 12001, 12002
|
138
|
+
let globalSeq = (Date.now() % 100) * 10000;
|
131
139
|
function messenger(type, options, target, ...args) {
|
132
|
-
|
133
|
-
options.seq = Date.now() % 100000;
|
140
|
+
options.seq = globalSeq++;
|
134
141
|
const { seq } = options;
|
135
142
|
// Message goes to extension page
|
136
143
|
if ("page" in target) {
|
@@ -160,9 +167,11 @@ function messenger(type, options, target, ...args) {
|
|
160
167
|
// Message tab directly
|
161
168
|
return manageConnection(type, options, target, async (attemptCount) => {
|
162
169
|
log.debug(type, seq, "↗️ sending message to tab", tabId, "frame", frameId, attemptLog(attemptCount));
|
163
|
-
return browser.tabs.sendMessage(tabId, makeMessage(type, args, target, options),
|
164
|
-
|
165
|
-
|
170
|
+
return browser.tabs.sendMessage(tabId, makeMessage(type, args, target, options), frameId === "allFrames"
|
171
|
+
? {}
|
172
|
+
: {
|
173
|
+
frameId,
|
174
|
+
});
|
166
175
|
});
|
167
176
|
}
|
168
177
|
function getMethod(type, target) {
|
package/distribution/types.d.ts
CHANGED
@@ -57,7 +57,7 @@ export type MessengerMessage = Message & {
|
|
57
57
|
};
|
58
58
|
export interface AnyTarget {
|
59
59
|
tabId?: number | "this";
|
60
|
-
frameId?: number;
|
60
|
+
frameId?: number | "allFrames";
|
61
61
|
page?: string;
|
62
62
|
}
|
63
63
|
export interface TopLevelFrame {
|
@@ -75,7 +75,7 @@ export interface KnownTarget {
|
|
75
75
|
}
|
76
76
|
export interface Target {
|
77
77
|
tabId: number;
|
78
|
-
frameId?: number;
|
78
|
+
frameId?: number | "allFrames";
|
79
79
|
}
|
80
80
|
export interface PageTarget {
|
81
81
|
tabId?: number | "this";
|