webext-messenger 0.25.2 → 0.26.0

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.
@@ -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
- // Not a UID. Signal / console noise compromise. They repeat every 100 seconds
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
- frameId,
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) {
@@ -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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webext-messenger",
3
- "version": "0.25.2",
3
+ "version": "0.26.0",
4
4
  "description": "Browser Extension component messaging framework",
5
5
  "keywords": [],
6
6
  "repository": "pixiebrix/webext-messenger",