webext-messenger 0.16.0 → 0.17.0-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.
@@ -6,6 +6,27 @@ import { debug } from "./shared.js";
6
6
  // This CANNOT be awaited because waiting for it means "I will handle the message."
7
7
  // If a message is received before this is ready, it will just have to be ignored.
8
8
  let thisTarget;
9
+ function compareTargets(to, thisTarget) {
10
+ for (const [key, value] of Object.entries(to)) {
11
+ if (thisTarget[key] === value) {
12
+ continue;
13
+ }
14
+ if (key !== "page") {
15
+ return false;
16
+ }
17
+ const toUrl = new URL(to.page, location.origin);
18
+ const thisUrl = new URL(thisTarget.page, location.origin);
19
+ if (toUrl.pathname !== thisUrl.pathname) {
20
+ return false;
21
+ }
22
+ for (const [parameterKey, parameterValue] of toUrl.searchParams) {
23
+ if (thisUrl.searchParams.get(parameterKey) !== parameterValue) {
24
+ return false;
25
+ }
26
+ }
27
+ }
28
+ return true;
29
+ }
9
30
  export function getActionForMessage(from, { ...to } // Clone object because we're editing it
10
31
  ) {
11
32
  var _a;
@@ -31,9 +52,7 @@ export function getActionForMessage(from, { ...to } // Clone object because we'r
31
52
  to.tabId = thisTarget.tabId;
32
53
  }
33
54
  // Every `target` key must match `thisTarget`
34
- const isThisTarget = Object.entries(to).every(
35
- // @ts-expect-error Optional properties
36
- ([key, value]) => thisTarget[key] === value);
55
+ const isThisTarget = compareTargets(to, thisTarget);
37
56
  if (!isThisTarget) {
38
57
  debug("The message’s target is", to, "but this is", thisTarget);
39
58
  }
@@ -45,7 +64,7 @@ export async function nameThisTarget() {
45
64
  if (!nameRequested && !thisTarget && !isContentScript()) {
46
65
  nameRequested = true;
47
66
  thisTarget = await messenger("__getTabData", {}, { page: "any" });
48
- thisTarget.page = location.pathname;
67
+ thisTarget.page = location.pathname + location.search;
49
68
  }
50
69
  }
51
70
  function __getTabData() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webext-messenger",
3
- "version": "0.16.0",
3
+ "version": "0.17.0-0",
4
4
  "description": "Browser Extension component messaging framework",
5
5
  "keywords": [],
6
6
  "repository": "pixiebrix/webext-messenger",