webext-messenger 0.24.0 → 0.25.0-0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,4 +5,6 @@ export * from "./types.js";
5
5
  export { getThisFrame, getTopLevelFrame } from "./thisTarget.js";
6
6
  export { toggleLogging } from "./logging.js";
7
7
  import { initPrivateApi } from "./thisTarget.js";
8
+ // Required side effect to better track errors:
9
+ // https://github.com/pixiebrix/webext-messenger/pull/80
8
10
  initPrivateApi();
@@ -4,15 +4,7 @@ export function isObject(value) {
4
4
  return typeof value === "object" && value !== null;
5
5
  }
6
6
  export class MessengerError extends Error {
7
- constructor() {
8
- super(...arguments);
9
- Object.defineProperty(this, "name", {
10
- enumerable: true,
11
- configurable: true,
12
- writable: true,
13
- value: "MessengerError"
14
- });
15
- }
7
+ name = "MessengerError";
16
8
  }
17
9
  // @ts-expect-error Wrong `errorConstructors` types
18
10
  errorConstructors.set("MessengerError", MessengerError);
@@ -106,9 +106,7 @@ const storeTabData = once(async () => {
106
106
  }
107
107
  catch (error) {
108
108
  tabDataStatus = "error";
109
- throw new MessengerError("Tab registration failed. This page won’t be able to receive messages that require tab information",
110
- // @ts-expect-error TODO: update lib to accept Error#cause
111
- { cause: error });
109
+ throw new MessengerError("Tab registration failed. This page won’t be able to receive messages that require tab information", { cause: error });
112
110
  }
113
111
  });
114
112
  export function __getTabData() {
@@ -131,6 +129,16 @@ export async function getTopLevelFrame() {
131
129
  };
132
130
  }
133
131
  export function initPrivateApi() {
132
+ // Improve DX by informing the developer that it's being loaded the wrong way
133
+ // https://github.com/pixiebrix/webext-messenger/issues/88
134
+ if (globalThis.__webextMessenger) {
135
+ // TODO: Use Error#cause after https://bugs.chromium.org/p/chromium/issues/detail?id=1211260
136
+ console.log(globalThis.__webextMessenger.replace(/^Error/, "webext-messenger"));
137
+ console.error("webext-messenger: Duplicate execution. This is a fatal error.\nhttps://github.com/pixiebrix/webext-messenger/issues/88");
138
+ return;
139
+ }
140
+ // Use Error to capture the stack and make it easier to find the cause
141
+ globalThis.__webextMessenger = new Error("First execution").stack;
134
142
  if (isExtensionContext()) {
135
143
  // Only `runtime` pages can handle this message but I can't remove it because its listener
136
144
  // also serves the purpose of throwing a specific error when no methods have been registered.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webext-messenger",
3
- "version": "0.24.0",
3
+ "version": "0.25.0-0",
4
4
  "description": "Browser Extension component messaging framework",
5
5
  "keywords": [],
6
6
  "repository": "pixiebrix/webext-messenger",
@@ -27,25 +27,25 @@
27
27
  "dependencies": {
28
28
  "p-retry": "^6.0.0",
29
29
  "serialize-error": "^11.0.2",
30
- "type-fest": "^4.3.1",
30
+ "type-fest": "^4.6.0",
31
31
  "webext-detect-page": "^4.1.1"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@parcel/config-webextension": "^2.6.2",
35
- "@sindresorhus/tsconfig": "^4.0.0",
36
- "@types/chrome": "^0.0.245",
37
- "@types/tape": "^5.6.1",
38
- "@types/webextension-polyfill": "^0.10.2",
35
+ "@sindresorhus/tsconfig": "^5.0.0",
36
+ "@types/chrome": "^0.0.248",
37
+ "@types/tape": "^5.6.3",
38
+ "@types/webextension-polyfill": "^0.10.5",
39
39
  "buffer": "^6.0.3",
40
- "eslint": "^8.50.0",
41
- "eslint-config-pixiebrix": "^0.27.2",
40
+ "eslint": "^8.52.0",
41
+ "eslint-config-pixiebrix": "^0.29.1",
42
42
  "events": "^3.3.0",
43
43
  "npm-run-all": "^4.1.5",
44
44
  "parcel": "^2.6.2",
45
45
  "path-browserify": "^1.0.1",
46
46
  "process": "^0.11.10",
47
47
  "stream-browserify": "^3.0.0",
48
- "tape": "^5.7.0",
48
+ "tape": "^5.7.2",
49
49
  "typescript": "^5.2.2",
50
50
  "webext-content-scripts": "^2.5.5",
51
51
  "webextension-polyfill": "^0.10.0"