webext-messenger 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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>>>(type: TType): PublicMethod;
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>>(type: TType): PublicMethod;
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 {};
@@ -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
- const response = await handler.call(sender, ...message.args).then((value) => ({ value }), (error) => ({
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.0",
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
  },