webext-messenger 0.22.0-4 → 0.22.0-5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  import { __getTabData } from "./thisTarget.js";
2
- import { Method } from "./types.js";
2
+ import { type Method } from "./types.js";
3
3
  declare global {
4
4
  interface MessengerMethods {
5
5
  __getTabData: typeof __getTabData;
@@ -1,4 +1,4 @@
1
1
  export * from "./receiver.js";
2
2
  export * from "./sender.js";
3
3
  export * from "./types.js";
4
- export { getThisTarget } from "./thisTarget.js";
4
+ export { getThisTarget, getTopLevelFrame } from "./thisTarget.js";
@@ -2,6 +2,6 @@
2
2
  export * from "./receiver.js";
3
3
  export * from "./sender.js";
4
4
  export * from "./types.js";
5
- export { getThisTarget } from "./thisTarget.js";
5
+ export { getThisTarget, getTopLevelFrame } from "./thisTarget.js";
6
6
  import { initPrivateApi } from "./thisTarget.js";
7
7
  initPrivateApi();
@@ -1,3 +1,3 @@
1
- import { Message } from "./types.js";
1
+ import { type Message } from "./types.js";
2
2
  export declare function isMessengerMessage(message: unknown): message is Message;
3
3
  export declare function registerMethods(methods: Partial<MessengerMethods>): void;
@@ -1,5 +1,5 @@
1
- import { PublicMethod, PublicMethodWithTarget, Options, Target, PageTarget } from "./types.js";
2
- import { SetReturnType } from "type-fest";
1
+ import { type PublicMethod, type PublicMethodWithTarget, type Options, type Target, type PageTarget } from "./types.js";
2
+ import { type SetReturnType } from "type-fest";
3
3
  export declare const errorTargetClosedEarly = "The target was closed before receiving a response";
4
4
  export declare const errorTabDoesntExist = "The tab doesn't exist";
5
5
  declare function messenger<Type extends keyof MessengerMethods, Method extends MessengerMethods[Type]>(type: Type, options: {
@@ -1,4 +1,4 @@
1
- import { JsonObject } from "type-fest";
1
+ import { type JsonObject } from "type-fest";
2
2
  declare type ErrorObject = {
3
3
  name?: string;
4
4
  stack?: string;
@@ -1,5 +1,6 @@
1
- import { AnyTarget, KnownTarget, Message, MessengerMeta, Sender } from "./types.js";
1
+ import { type AnyTarget, type KnownTarget, type TopLevelFrame, type Message, type MessengerMeta, type Sender } from "./types.js";
2
2
  export declare function getActionForMessage(from: Sender, message: Message): "respond" | "forward" | "ignore";
3
3
  export declare function __getTabData(this: MessengerMeta): AnyTarget;
4
4
  export declare function getThisTarget(): Promise<KnownTarget>;
5
+ export declare function getTopLevelFrame(): Promise<TopLevelFrame>;
5
6
  export declare function initPrivateApi(): void;
@@ -116,6 +116,16 @@ export async function getThisTarget() {
116
116
  await storeTabData(); // It should already have been called by we still need to await it
117
117
  return thisTarget;
118
118
  }
119
+ export async function getTopLevelFrame() {
120
+ const { tabId } = await getThisTarget();
121
+ if (typeof tabId !== "number") {
122
+ throw new TypeError("This target is not in a tab");
123
+ }
124
+ return {
125
+ tabId,
126
+ frameId: 0,
127
+ };
128
+ }
119
129
  export function initPrivateApi() {
120
130
  if (isExtensionContext()) {
121
131
  // Only `runtime` pages can handle this message but I can't remove it because its listener
@@ -1,6 +1,6 @@
1
- import { Runtime } from "webextension-polyfill";
2
- import { Asyncify, ValueOf } from "type-fest";
3
- import { ErrorObject } from "serialize-error";
1
+ import { type Runtime } from "webextension-polyfill";
2
+ import { type Asyncify, type ValueOf } from "type-fest";
3
+ import { type ErrorObject } from "serialize-error";
4
4
  declare global {
5
5
  interface MessengerMethods {
6
6
  _: Method;
@@ -11,9 +11,9 @@ declare type ActuallyOmitThisParameter<T> = T extends (...args: infer A) => infe
11
11
  /** Removes the `this` type and ensure it's always Promised */
12
12
  export declare type PublicMethod<Method extends ValueOf<MessengerMethods>> = Asyncify<ActuallyOmitThisParameter<Method>>;
13
13
  export declare type PublicMethodWithTarget<Method extends ValueOf<MessengerMethods>> = WithTarget<PublicMethod<Method>>;
14
- export interface MessengerMeta {
14
+ export declare type MessengerMeta = {
15
15
  trace: Sender[];
16
- }
16
+ };
17
17
  declare type RawMessengerResponse = {
18
18
  value: unknown;
19
19
  } | {
@@ -25,14 +25,14 @@ export declare type MessengerResponse = RawMessengerResponse & {
25
25
  };
26
26
  declare type Arguments = any[];
27
27
  export declare type Method = (this: MessengerMeta, ...args: Arguments) => Promise<unknown>;
28
- export interface Options {
28
+ export declare type Options = {
29
29
  /**
30
30
  * "Notifications" won't await the response, return values, attempt retries, nor throw errors
31
31
  * @default false
32
32
  */
33
33
  isNotification?: boolean;
34
34
  trace?: Sender[];
35
- }
35
+ };
36
36
  export declare type Message<LocalArguments extends Arguments = Arguments> = {
37
37
  type: keyof MessengerMethods;
38
38
  args: LocalArguments;
@@ -47,22 +47,26 @@ export declare type MessengerMessage = Message & {
47
47
  /** Guarantees that a message is meant to be handled by this library */
48
48
  __webextMessenger: true;
49
49
  };
50
- export interface AnyTarget {
50
+ export declare type AnyTarget = {
51
51
  tabId?: number | "this";
52
52
  frameId?: number;
53
53
  page?: string;
54
- }
55
- export interface KnownTarget {
54
+ };
55
+ export declare type TopLevelFrame = {
56
+ tabId: number;
57
+ frameId: 0;
58
+ };
59
+ export declare type KnownTarget = {
56
60
  tabId?: number;
57
61
  frameId?: number;
58
62
  page: string;
59
- }
60
- export interface Target {
63
+ };
64
+ export declare type Target = {
61
65
  tabId: number;
62
66
  frameId?: number;
63
- }
64
- export interface PageTarget {
67
+ };
68
+ export declare type PageTarget = {
65
69
  tabId?: number | "this";
66
70
  page: string;
67
- }
71
+ };
68
72
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webext-messenger",
3
- "version": "0.22.0-4",
3
+ "version": "0.22.0-5",
4
4
  "description": "Browser Extension component messaging framework",
5
5
  "keywords": [],
6
6
  "repository": "pixiebrix/webext-messenger",
@@ -21,25 +21,19 @@
21
21
  "dependencies": {
22
22
  "p-retry": "^5.1.1",
23
23
  "serialize-error": "^11.0.0",
24
- "type-fest": "^2.13.0",
24
+ "type-fest": "^3.2.0",
25
25
  "webext-detect-page": "^4.0.1",
26
26
  "webext-tools": "^1.1.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@parcel/config-webextension": "^2.6.0",
29
+ "@parcel/config-webextension": "^2.8.0",
30
30
  "@sindresorhus/tsconfig": "^3.0.1",
31
- "@types/chrome": "^0.0.188",
31
+ "@types/chrome": "^0.0.203",
32
32
  "@types/tape": "^4.13.2",
33
33
  "@types/webextension-polyfill": "^0.9.0",
34
- "@typescript-eslint/eslint-plugin": "^5.27.0",
35
- "@typescript-eslint/parser": "^5.27.0",
36
34
  "buffer": "^6.0.3",
37
- "eslint": "^8.17.0",
38
- "eslint-config-prettier": "^8.5.0",
39
- "eslint-config-xo": "^0.41.0",
40
- "eslint-config-xo-typescript": "^0.51.1",
41
- "eslint-plugin-import": "^2.26.0",
42
- "eslint-plugin-unicorn": "^42.0.0",
35
+ "eslint": "^8.28.0",
36
+ "eslint-config-pixiebrix": "^0.20.0",
43
37
  "events": "^3.3.0",
44
38
  "npm-run-all": "^4.1.5",
45
39
  "parcel": "^2.6.0",
@@ -47,9 +41,9 @@
47
41
  "process": "^0.11.10",
48
42
  "stream-browserify": "^3.0.0",
49
43
  "tape": "^5.5.3",
50
- "typescript": "^4.7.3",
44
+ "typescript": "^4.9.3",
51
45
  "webext-content-scripts": "^1.0.2",
52
- "webextension-polyfill": "^0.9.0"
46
+ "webextension-polyfill": "^0.10.0"
53
47
  },
54
48
  "alias": {
55
49
  "./this-stuff-is-just-for-local-parcel-tests": "https://github.com/parcel-bundler/parcel/issues/4936",