webext-messenger 0.25.1 → 0.25.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- import { isBackground, isContentScript, isExtensionContext, } from "webext-detect-page";
1
+ import { getContextName, isBackground, isContentScript, isExtensionContext, } from "webext-detect-page";
2
2
  import { messenger } from "./sender.js";
3
3
  import { registerMethods } from "./receiver.js";
4
4
  import { MessengerError, once } from "./shared.js";
@@ -112,11 +112,17 @@ const storeTabData = once(async () => {
112
112
  export function __getTabData() {
113
113
  return { tabId: this.trace[0]?.tab?.id, frameId: this.trace[0]?.frameId };
114
114
  }
115
+ // TODO: Add tests
115
116
  export async function getThisFrame() {
116
117
  await storeTabData(); // It should already have been called but we still need to await it
117
118
  const { tabId, frameId } = thisTarget;
118
119
  if (typeof tabId !== "number" || typeof frameId !== "number") {
119
- throw new TypeError("This target is not in a frame");
120
+ let moreInfo = "(error retrieving context information)";
121
+ try {
122
+ moreInfo = `(context: ${getContextName()}, url: ${globalThis.location?.href})`;
123
+ }
124
+ catch { }
125
+ throw new TypeError(`This target is not in a frame ${moreInfo}`);
120
126
  }
121
127
  // Rebuild object to return exactly these two properties and nothing more
122
128
  return { tabId, frameId };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webext-messenger",
3
- "version": "0.25.1",
3
+ "version": "0.25.2",
4
4
  "description": "Browser Extension component messaging framework",
5
5
  "keywords": [],
6
6
  "repository": "pixiebrix/webext-messenger",