webext-messenger 0.7.0 → 0.7.1
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.
- package/distribution/index.d.ts +3 -2
- package/distribution/index.js +2 -1
- package/package.json +2 -1
package/distribution/index.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
/// <reference types="firefox-webext-browser" />
|
2
|
+
import { Asyncify } from "type-fest";
|
2
3
|
declare global {
|
3
4
|
interface MessengerMethods {
|
4
5
|
_: Method;
|
@@ -17,11 +18,11 @@ declare type WithTarget<TMethod> = TMethod extends (...args: infer PreviousArgum
|
|
17
18
|
* Replicates the original method, including its types.
|
18
19
|
* To be called in the sender’s end.
|
19
20
|
*/
|
20
|
-
export declare function getContentScriptMethod<TType extends keyof MessengerMethods, TMethod extends MessengerMethods[TType], PublicMethod extends WithTarget<ActuallyOmitThisParameter<TMethod
|
21
|
+
export declare function getContentScriptMethod<TType extends keyof MessengerMethods, TMethod extends MessengerMethods[TType], PublicMethod extends WithTarget<Asyncify<ActuallyOmitThisParameter<TMethod>>>>(type: TType): PublicMethod;
|
21
22
|
/**
|
22
23
|
* Replicates the original method, including its types.
|
23
24
|
* To be called in the sender’s end.
|
24
25
|
*/
|
25
|
-
export declare function getMethod<TType extends keyof MessengerMethods, TMethod extends MessengerMethods[TType], PublicMethod extends ActuallyOmitThisParameter<TMethod
|
26
|
+
export declare function getMethod<TType extends keyof MessengerMethods, TMethod extends MessengerMethods[TType], PublicMethod extends Asyncify<ActuallyOmitThisParameter<TMethod>>>(type: TType): PublicMethod;
|
26
27
|
export declare function registerMethods(methods: Partial<MessengerMethods>): void;
|
27
28
|
export {};
|
package/distribution/index.js
CHANGED
@@ -19,7 +19,8 @@ async function handleMessage(message, sender) {
|
|
19
19
|
throw new Error("No handler registered for " + message.type);
|
20
20
|
}
|
21
21
|
console.debug(`Messenger:`, message.type, message.args, "from", { sender });
|
22
|
-
|
22
|
+
// The handler could actually be a synchronous function
|
23
|
+
const response = await Promise.resolve(handler.call(sender, ...message.args)).then((value) => ({ value }), (error) => ({
|
23
24
|
// Errors must be serialized because the stacktraces are currently lost on Chrome and
|
24
25
|
// https://github.com/mozilla/webextension-polyfill/issues/210
|
25
26
|
error: serializeError(error),
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "webext-messenger",
|
3
|
-
"version": "0.7.
|
3
|
+
"version": "0.7.1",
|
4
4
|
"description": "Browser Extension component messaging framework",
|
5
5
|
"keywords": [],
|
6
6
|
"repository": "pixiebrix/extension-messaging",
|
@@ -69,6 +69,7 @@
|
|
69
69
|
},
|
70
70
|
"dependencies": {
|
71
71
|
"serialize-error": "^8.1.0",
|
72
|
+
"type-fest": "^2.3.4",
|
72
73
|
"webext-detect-page": "^3.0.2",
|
73
74
|
"webextension-polyfill": "^0.8.0"
|
74
75
|
},
|