webext-messenger
Advanced tools
Comparing version 0.24.0 to 0.25.0-0
@@ -8,2 +8,4 @@ // Imports must use the .js extension because ESM requires it and TS refuses to rewrite .ts to .js | ||
import { initPrivateApi } from "./thisTarget.js"; | ||
// Required side effect to better track errors: | ||
// https://github.com/pixiebrix/webext-messenger/pull/80 | ||
initPrivateApi(); |
@@ -7,11 +7,3 @@ import { errorConstructors } from "serialize-error"; | ||
export class MessengerError extends Error { | ||
constructor() { | ||
super(...arguments); | ||
Object.defineProperty(this, "name", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: "MessengerError" | ||
}); | ||
} | ||
name = "MessengerError"; | ||
} | ||
@@ -18,0 +10,0 @@ // @ts-expect-error Wrong `errorConstructors` types |
@@ -109,5 +109,3 @@ import { isBackground, isContentScript, isExtensionContext, } from "webext-detect-page"; | ||
tabDataStatus = "error"; | ||
throw new MessengerError("Tab registration failed. This page won’t be able to receive messages that require tab information", | ||
// @ts-expect-error TODO: update lib to accept Error#cause | ||
{ cause: error }); | ||
throw new MessengerError("Tab registration failed. This page won’t be able to receive messages that require tab information", { cause: error }); | ||
} | ||
@@ -135,2 +133,12 @@ }); | ||
export function initPrivateApi() { | ||
// Improve DX by informing the developer that it's being loaded the wrong way | ||
// https://github.com/pixiebrix/webext-messenger/issues/88 | ||
if (globalThis.__webextMessenger) { | ||
// TODO: Use Error#cause after https://bugs.chromium.org/p/chromium/issues/detail?id=1211260 | ||
console.log(globalThis.__webextMessenger.replace(/^Error/, "webext-messenger")); | ||
console.error("webext-messenger: Duplicate execution. This is a fatal error.\nhttps://github.com/pixiebrix/webext-messenger/issues/88"); | ||
return; | ||
} | ||
// Use Error to capture the stack and make it easier to find the cause | ||
globalThis.__webextMessenger = new Error("First execution").stack; | ||
if (isExtensionContext()) { | ||
@@ -137,0 +145,0 @@ // Only `runtime` pages can handle this message but I can't remove it because its listener |
{ | ||
"name": "webext-messenger", | ||
"version": "0.24.0", | ||
"version": "0.25.0-0", | ||
"description": "Browser Extension component messaging framework", | ||
@@ -30,3 +30,3 @@ "keywords": [], | ||
"serialize-error": "^11.0.2", | ||
"type-fest": "^4.3.1", | ||
"type-fest": "^4.6.0", | ||
"webext-detect-page": "^4.1.1" | ||
@@ -36,9 +36,9 @@ }, | ||
"@parcel/config-webextension": "^2.6.2", | ||
"@sindresorhus/tsconfig": "^4.0.0", | ||
"@types/chrome": "^0.0.245", | ||
"@types/tape": "^5.6.1", | ||
"@types/webextension-polyfill": "^0.10.2", | ||
"@sindresorhus/tsconfig": "^5.0.0", | ||
"@types/chrome": "^0.0.248", | ||
"@types/tape": "^5.6.3", | ||
"@types/webextension-polyfill": "^0.10.5", | ||
"buffer": "^6.0.3", | ||
"eslint": "^8.50.0", | ||
"eslint-config-pixiebrix": "^0.27.2", | ||
"eslint": "^8.52.0", | ||
"eslint-config-pixiebrix": "^0.29.1", | ||
"events": "^3.3.0", | ||
@@ -50,3 +50,3 @@ "npm-run-all": "^4.1.5", | ||
"stream-browserify": "^3.0.0", | ||
"tape": "^5.7.0", | ||
"tape": "^5.7.2", | ||
"typescript": "^5.2.2", | ||
@@ -53,0 +53,0 @@ "webext-content-scripts": "^2.5.5", |
30343
594
Updatedtype-fest@^4.6.0