webext-messenger 0.28.0 → 0.29.0-0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  import { serializeError } from "serialize-error";
2
- import { getContextName } from "webext-detect-page";
2
+ import { getContextName } from "webext-detect";
3
3
  import { messenger } from "./sender.js";
4
4
  import { isObject, MessengerError, __webextMessenger } from "./shared.js";
5
5
  import { log } from "./logging.js";
@@ -1,5 +1,5 @@
1
1
  import pRetry from "p-retry";
2
- import { isBackground } from "webext-detect-page";
2
+ import { isBackground } from "webext-detect";
3
3
  import { deserializeError } from "serialize-error";
4
4
  import { isObject, MessengerError, __webextMessenger } from "./shared.js";
5
5
  import { log } from "./logging.js";
@@ -113,7 +113,10 @@ async function manageMessage(type, target, seq, retry, sendMessage) {
113
113
  log.debug(type, seq, "will retry. Attempt", error.attemptNumber);
114
114
  },
115
115
  }).catch((error) => {
116
- if (error?.message === _errorNonExistingTarget) {
116
+ if (error &&
117
+ typeof error === "object" &&
118
+ "message" in error &&
119
+ error?.message === _errorNonExistingTarget) {
117
120
  throw new MessengerError(`The target ${JSON.stringify(target)} for ${type} was not found`);
118
121
  }
119
122
  events.dispatchEvent(new CustomEvent("attempts-exhausted", {
@@ -1,4 +1,4 @@
1
- import { isBackground, isContentScript } from "webext-detect-page";
1
+ import { isBackground, isContentScript } from "webext-detect";
2
2
  export function compareTargets(to, thisTarget) {
3
3
  for (const [key, value] of Object.entries(to)) {
4
4
  if (thisTarget[key] === value) {
@@ -1,7 +1,7 @@
1
1
  import { assert, describe, test, vi } from "vitest";
2
2
  import { getActionForMessage } from "./targetLogic.js";
3
- import { isContentScript, isBackground } from "webext-detect-page";
4
- vi.mock("webext-detect-page");
3
+ import { isContentScript, isBackground } from "webext-detect";
4
+ vi.mock("webext-detect");
5
5
  const tab = {
6
6
  id: 1,
7
7
  url: "http://example.com",
@@ -1,4 +1,4 @@
1
- import { getContextName, isBackground, isExtensionContext, } from "webext-detect-page";
1
+ import { getContextName, isBackground, isExtensionContext, isOffscreenDocument, } from "webext-detect";
2
2
  import { messenger } from "./sender.js";
3
3
  import { registerMethods } from "./receiver.js";
4
4
  import { MessengerError, once } from "./shared.js";
@@ -28,19 +28,21 @@ import { pEvent } from "p-event";
28
28
  // If a message is received before this is ready, it will just have to be ignored.
29
29
  export const thisTarget = isBackground()
30
30
  ? { page: "background" }
31
- : {
32
- get page() {
33
- // Extension pages have relative URLs to simplify comparison
34
- const origin = location.protocol.startsWith("http")
35
- ? location.origin
36
- : "";
37
- // Don't use the hash
38
- return origin + location.pathname + location.search;
39
- },
40
- };
31
+ : (isOffscreenDocument()
32
+ ? { page: "offscreen" }
33
+ : {
34
+ get page() {
35
+ // Extension pages have relative URLs to simplify comparison
36
+ const origin = location.protocol.startsWith("http")
37
+ ? location.origin
38
+ : "";
39
+ // Don't use the hash
40
+ return origin + location.pathname + location.search;
41
+ },
42
+ });
41
43
  let tabDataStatus =
42
44
  // The background page doesn't have a tab
43
- isBackground() ? "not-needed" : "needed";
45
+ isBackground() || isOffscreenDocument() ? "not-needed" : "needed";
44
46
  export function getTabDataStatus() {
45
47
  return tabDataStatus;
46
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webext-messenger",
3
- "version": "0.28.0",
3
+ "version": "0.29.0-0",
4
4
  "description": "Browser Extension component messaging framework",
5
5
  "keywords": [],
6
6
  "repository": "pixiebrix/webext-messenger",
@@ -29,31 +29,32 @@
29
29
  "p-event": "^6.0.1",
30
30
  "p-retry": "^6.2.0",
31
31
  "serialize-error": "^11.0.3",
32
- "type-fest": "^4.18.3",
33
- "webext-detect-page": "^5.0.1"
32
+ "type-fest": "^4.26.1",
33
+ "webext-detect": "^5.3.1",
34
+ "webext-events": "^3.1.1"
34
35
  },
35
36
  "@parcel/resolver-default": {
36
37
  "packageExports": true
37
38
  },
38
39
  "devDependencies": {
39
40
  "@parcel/config-webextension": "^2.11.0",
40
- "@sindresorhus/tsconfig": "^5.0.0",
41
- "@types/chrome": "^0.0.268",
41
+ "@sindresorhus/tsconfig": "^6.0.0",
42
+ "@types/chrome": "^0.0.279",
42
43
  "@types/tape": "^5.6.4",
43
- "@types/webextension-polyfill": "^0.10.7",
44
+ "@types/webextension-polyfill": "^0.12.1",
44
45
  "buffer": "^6.0.3",
45
46
  "eslint": "^8.57.0",
46
- "eslint-config-pixiebrix": "^0.39.0",
47
+ "eslint-config-pixiebrix": "^0.40.1",
47
48
  "events": "^3.3.0",
48
49
  "npm-run-all": "^4.1.5",
49
50
  "parcel": "^2.11.0",
50
51
  "path-browserify": "^1.0.1",
51
52
  "process": "^0.11.10",
52
53
  "stream-browserify": "^3.0.0",
53
- "tape": "^5.7.5",
54
- "typescript": "^5.4.5",
55
- "vitest": "^1.6.0",
56
- "webext-content-scripts": "^2.6.1",
54
+ "tape": "^5.9.0",
55
+ "typescript": "^5.6.3",
56
+ "vitest": "^2.1.4",
57
+ "webext-content-scripts": "^2.7.0",
57
58
  "webextension-polyfill": "^0.12.0"
58
59
  },
59
60
  "targets": {
@@ -73,7 +74,8 @@
73
74
  "run": {
74
75
  "startUrl": [
75
76
  "https://fregante.github.io/pixiebrix-testing-ground/Will-call-background-methods",
76
- "https://fregante.github.io/pixiebrix-testing-ground/Will-call-other-CS-via-background"
77
+ "https://fregante.github.io/pixiebrix-testing-ground/Will-call-other-CS-via-background",
78
+ "https://fregante.github.io/pixiebrix-testing-ground/Will-call-offscreen-methods"
77
79
  ]
78
80
  }
79
81
  }