Skip to content

Commit

Permalink
re-enable sendResponse. Resolves #54
Browse files Browse the repository at this point in the history
  • Loading branch information
Lusito committed Jan 8, 2023
1 parent 8641616 commit b803c68
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
12 changes: 6 additions & 6 deletions fixes/runtime.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@
}
]
},
"events.%onMessage.parameters.%sendResponse": null,
"events.%onMessage.parameters.%sendResponse.description": "Function to call (at most once) when you have a response. This is an alternative to returning a Promise. The argument should be any JSON-ifiable object. If you have more than one <code>onMessage</code> listener in the same document, then only one may send a response. This function becomes invalid when the event listener returns, unless you return true from the event listener to indicate you wish to send a response asynchronously (this will keep the message channel open to the other end until <code>sendResponse</code> is called).",
"events.%onMessage.returns": {
"type": "Promise<any>",
"type": "Promise<any> | true",
"optional": true,
"description": "Return a <code>Promise</code> from the listener function and resolve the promise when the response is ready."
"description": "Return a <code>Promise</code> from the listener function and resolve the promise when the response is ready. Alternatively, return true and call sendResponse."
},
"events.%onMessageExternal.parameters.%sendResponse": null,
"events.%onMessageExternal.parameters.%sendResponse.description": "Function to call (at most once) when you have a response. This is an alternative to returning a Promise. The argument should be any JSON-ifiable object. If you have more than one <code>onMessage</code> listener in the same document, then only one may send a response. This function becomes invalid when the event listener returns, unless you return true from the event listener to indicate you wish to send a response asynchronously (this will keep the message channel open to the other end until <code>sendResponse</code> is called).",
"events.%onMessageExternal.returns": {
"type": "Promise<any>",
"type": "Promise<any> | true",
"optional": true,
"description": "Return a <code>Promise</code> from the listener function and resolve the promise when the response is ready."
"description": "Return a <code>Promise</code> from the listener function and resolve the promise when the response is ready. Alternatively, return true and call sendResponse."
}
}
20 changes: 17 additions & 3 deletions out/namespaces/runtime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,16 +438,30 @@ export namespace Runtime {
*
* @param message Optional. The message sent by the calling script.
* @param sender
* @param sendResponse Function to call (at most once) when you have a response. This is an alternative to returning a
* Promise. The argument should be any JSON-ifiable object. If you have more than one <code>onMessage</code>
* listener in the same document, then only one may send a response. This function becomes invalid when the event listener
* returns, unless you return true from the event listener to indicate you wish to send a response asynchronously (this
* will keep the message channel open to the other end until <code>sendResponse</code> is called).
*/
onMessage: Events.Event<(message: any, sender: MessageSender) => Promise<any> | void>;
onMessage: Events.Event<
(message: any, sender: MessageSender, sendResponse: () => void) => Promise<any> | true | void
>;

/**
* Fired when a message is sent from another extension/app. Cannot be used in a content script.
*
* @param message Optional. The message sent by the calling script.
* @param sender
*/
onMessageExternal: Events.Event<(message: any, sender: MessageSender) => Promise<any> | void>;
* @param sendResponse Function to call (at most once) when you have a response. This is an alternative to returning a
* Promise. The argument should be any JSON-ifiable object. If you have more than one <code>onMessage</code>
* listener in the same document, then only one may send a response. This function becomes invalid when the event listener
* returns, unless you return true from the event listener to indicate you wish to send a response asynchronously (this
* will keep the message channel open to the other end until <code>sendResponse</code> is called).
*/
onMessageExternal: Events.Event<
(message: any, sender: MessageSender, sendResponse: () => void) => Promise<any> | true | void
>;

/**
* This will be defined during an API method callback if there was an error
Expand Down

0 comments on commit b803c68

Please sign in to comment.