webext-messenger
Advanced tools
Comparing version 0.22.0-4 to 0.22.0-5
import { __getTabData } from "./thisTarget.js"; | ||
import { Method } from "./types.js"; | ||
import { type Method } from "./types.js"; | ||
declare global { | ||
@@ -4,0 +4,0 @@ interface MessengerMethods { |
export * from "./receiver.js"; | ||
export * from "./sender.js"; | ||
export * from "./types.js"; | ||
export { getThisTarget } from "./thisTarget.js"; | ||
export { getThisTarget, getTopLevelFrame } from "./thisTarget.js"; |
@@ -5,4 +5,4 @@ // Imports must use the .js extension because ESM requires it and TS refuses to rewrite .ts to .js | ||
export * from "./types.js"; | ||
export { getThisTarget } from "./thisTarget.js"; | ||
export { getThisTarget, getTopLevelFrame } from "./thisTarget.js"; | ||
import { initPrivateApi } from "./thisTarget.js"; | ||
initPrivateApi(); |
@@ -1,3 +0,3 @@ | ||
import { Message } from "./types.js"; | ||
import { type Message } from "./types.js"; | ||
export declare function isMessengerMessage(message: unknown): message is Message; | ||
export declare function registerMethods(methods: Partial<MessengerMethods>): void; |
@@ -1,3 +0,3 @@ | ||
import { PublicMethod, PublicMethodWithTarget, Options, Target, PageTarget } from "./types.js"; | ||
import { SetReturnType } from "type-fest"; | ||
import { type PublicMethod, type PublicMethodWithTarget, type Options, type Target, type PageTarget } from "./types.js"; | ||
import { type SetReturnType } from "type-fest"; | ||
export declare const errorTargetClosedEarly = "The target was closed before receiving a response"; | ||
@@ -4,0 +4,0 @@ export declare const errorTabDoesntExist = "The tab doesn't exist"; |
@@ -1,2 +0,2 @@ | ||
import { JsonObject } from "type-fest"; | ||
import { type JsonObject } from "type-fest"; | ||
declare type ErrorObject = { | ||
@@ -3,0 +3,0 @@ name?: string; |
@@ -1,5 +0,6 @@ | ||
import { AnyTarget, KnownTarget, Message, MessengerMeta, Sender } from "./types.js"; | ||
import { type AnyTarget, type KnownTarget, type TopLevelFrame, type Message, type MessengerMeta, type Sender } from "./types.js"; | ||
export declare function getActionForMessage(from: Sender, message: Message): "respond" | "forward" | "ignore"; | ||
export declare function __getTabData(this: MessengerMeta): AnyTarget; | ||
export declare function getThisTarget(): Promise<KnownTarget>; | ||
export declare function getTopLevelFrame(): Promise<TopLevelFrame>; | ||
export declare function initPrivateApi(): void; |
@@ -119,2 +119,12 @@ import { isBackground, isContentScript, isExtensionContext, } from "webext-detect-page"; | ||
} | ||
export async function getTopLevelFrame() { | ||
const { tabId } = await getThisTarget(); | ||
if (typeof tabId !== "number") { | ||
throw new TypeError("This target is not in a tab"); | ||
} | ||
return { | ||
tabId, | ||
frameId: 0, | ||
}; | ||
} | ||
export function initPrivateApi() { | ||
@@ -121,0 +131,0 @@ if (isExtensionContext()) { |
@@ -1,4 +0,4 @@ | ||
import { Runtime } from "webextension-polyfill"; | ||
import { Asyncify, ValueOf } from "type-fest"; | ||
import { ErrorObject } from "serialize-error"; | ||
import { type Runtime } from "webextension-polyfill"; | ||
import { type Asyncify, type ValueOf } from "type-fest"; | ||
import { type ErrorObject } from "serialize-error"; | ||
declare global { | ||
@@ -14,5 +14,5 @@ interface MessengerMethods { | ||
export declare type PublicMethodWithTarget<Method extends ValueOf<MessengerMethods>> = WithTarget<PublicMethod<Method>>; | ||
export interface MessengerMeta { | ||
export declare type MessengerMeta = { | ||
trace: Sender[]; | ||
} | ||
}; | ||
declare type RawMessengerResponse = { | ||
@@ -29,3 +29,3 @@ value: unknown; | ||
export declare type Method = (this: MessengerMeta, ...args: Arguments) => Promise<unknown>; | ||
export interface Options { | ||
export declare type Options = { | ||
/** | ||
@@ -37,3 +37,3 @@ * "Notifications" won't await the response, return values, attempt retries, nor throw errors | ||
trace?: Sender[]; | ||
} | ||
}; | ||
export declare type Message<LocalArguments extends Arguments = Arguments> = { | ||
@@ -53,20 +53,24 @@ type: keyof MessengerMethods; | ||
}; | ||
export interface AnyTarget { | ||
export declare type AnyTarget = { | ||
tabId?: number | "this"; | ||
frameId?: number; | ||
page?: string; | ||
} | ||
export interface KnownTarget { | ||
}; | ||
export declare type TopLevelFrame = { | ||
tabId: number; | ||
frameId: 0; | ||
}; | ||
export declare type KnownTarget = { | ||
tabId?: number; | ||
frameId?: number; | ||
page: string; | ||
} | ||
export interface Target { | ||
}; | ||
export declare type Target = { | ||
tabId: number; | ||
frameId?: number; | ||
} | ||
export interface PageTarget { | ||
}; | ||
export declare type PageTarget = { | ||
tabId?: number | "this"; | ||
page: string; | ||
} | ||
}; | ||
export {}; |
{ | ||
"name": "webext-messenger", | ||
"version": "0.22.0-4", | ||
"version": "0.22.0-5", | ||
"description": "Browser Extension component messaging framework", | ||
@@ -24,3 +24,3 @@ "keywords": [], | ||
"serialize-error": "^11.0.0", | ||
"type-fest": "^2.13.0", | ||
"type-fest": "^3.2.0", | ||
"webext-detect-page": "^4.0.1", | ||
@@ -30,16 +30,10 @@ "webext-tools": "^1.1.0" | ||
"devDependencies": { | ||
"@parcel/config-webextension": "^2.6.0", | ||
"@parcel/config-webextension": "^2.8.0", | ||
"@sindresorhus/tsconfig": "^3.0.1", | ||
"@types/chrome": "^0.0.188", | ||
"@types/chrome": "^0.0.203", | ||
"@types/tape": "^4.13.2", | ||
"@types/webextension-polyfill": "^0.9.0", | ||
"@typescript-eslint/eslint-plugin": "^5.27.0", | ||
"@typescript-eslint/parser": "^5.27.0", | ||
"buffer": "^6.0.3", | ||
"eslint": "^8.17.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-config-xo": "^0.41.0", | ||
"eslint-config-xo-typescript": "^0.51.1", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-unicorn": "^42.0.0", | ||
"eslint": "^8.28.0", | ||
"eslint-config-pixiebrix": "^0.20.0", | ||
"events": "^3.3.0", | ||
@@ -52,5 +46,5 @@ "npm-run-all": "^4.1.5", | ||
"tape": "^5.5.3", | ||
"typescript": "^4.7.3", | ||
"typescript": "^4.9.3", | ||
"webext-content-scripts": "^1.0.2", | ||
"webextension-polyfill": "^0.9.0" | ||
"webextension-polyfill": "^0.10.0" | ||
}, | ||
@@ -57,0 +51,0 @@ "alias": { |
27294
18
553
+ Addedtype-fest@3.13.1(transitive)
Updatedtype-fest@^3.2.0