webext-messenger 0.29.0-0 → 0.29.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.
@@ -26,22 +26,24 @@ import { pEvent } from "p-event";
26
26
  // Soft warning: Race conditions are possible.
27
27
  // This CANNOT be awaited because waiting for it means "I will handle the message."
28
28
  // If a message is received before this is ready, it will just have to be ignored.
29
- export const thisTarget = isBackground()
30
- ? { page: "background" }
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
- });
29
+ export const thisTarget = (() => {
30
+ if (isBackground())
31
+ return { page: "background" };
32
+ if (isOffscreenDocument())
33
+ return { page: "offscreen" };
34
+ return {
35
+ get page() {
36
+ // Extension pages have relative URLs to simplify comparison
37
+ const origin = location.protocol.startsWith("http")
38
+ ? location.origin
39
+ : "";
40
+ // Don't use the hash
41
+ return origin + location.pathname + location.search;
42
+ },
43
+ };
44
+ })();
43
45
  let tabDataStatus =
44
- // The background page doesn't have a tab
46
+ // Exclude contexts that don't have a tab associated to them
45
47
  isBackground() || isOffscreenDocument() ? "not-needed" : "needed";
46
48
  export function getTabDataStatus() {
47
49
  return tabDataStatus;
@@ -53,7 +55,7 @@ const storeTabData = once(async () => {
53
55
  // If the page is prerendering, wait for the change to be able to get the tab data so the frameId is correct
54
56
  // https://developer.mozilla.org/en-US/docs/Web/API/Document/prerenderingchange_event
55
57
  if ("prerendering" in document && Boolean(document.prerendering)) {
56
- await pEvent(document, 'prerenderingchange');
58
+ await pEvent(document, "prerenderingchange");
57
59
  }
58
60
  try {
59
61
  tabDataStatus = "pending";
@@ -75,8 +77,7 @@ export async function getThisFrame() {
75
77
  if (typeof tabId !== "number" || typeof frameId !== "number") {
76
78
  let moreInfo = "(error retrieving context information)";
77
79
  try {
78
- moreInfo = `(context: ${getContextName()}, url: ${globalThis.location
79
- ?.href})`;
80
+ moreInfo = `(context: ${getContextName()}, url: ${globalThis.location?.href})`;
80
81
  }
81
82
  catch { }
82
83
  throw new TypeError(`This target is not in a frame ${moreInfo}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webext-messenger",
3
- "version": "0.29.0-0",
3
+ "version": "0.29.0",
4
4
  "description": "Browser Extension component messaging framework",
5
5
  "keywords": [],
6
6
  "repository": "pixiebrix/webext-messenger",
package/readme.md CHANGED
@@ -19,7 +19,6 @@ import messenger from "webext-messenger";
19
19
 
20
20
  - [Initial considerations for this library](https://github.com/pixiebrix/webext-messenger/issues/1)
21
21
 
22
-
23
22
  ## npm publishing
24
23
 
25
24
  Collaborators can publish a new version of what's on main [via "workflow_dispatch"](https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/) under [Actions » Publish](https://github.com/pixiebrix/webext-messenger/actions/workflows/npm-publish.yml)