File tree Expand file tree Collapse file tree 1 file changed +9
-16
lines changed
Expand file tree Collapse file tree 1 file changed +9
-16
lines changed Original file line number Diff line number Diff line change @@ -23,24 +23,10 @@ export function isMessengerMessage(message: unknown): message is Message {
2323 ) ;
2424}
2525
26- type SendResponse = ( response : unknown ) => void ;
27-
28- /** Thin Promise-to-sendResponse converter. Don't add logic here */
29- async function adaptResponse (
30- sendResponse : SendResponse ,
31- response : Promise < unknown > ,
32- ) : Promise < void > {
33- try {
34- sendResponse ( await response ) ;
35- } catch ( error ) {
36- sendResponse ( { __webextMessenger : true , error : serializeError ( error ) } ) ;
37- }
38- }
39-
4026function onMessageListener (
4127 message : unknown ,
4228 sender : Sender ,
43- sendResponse : SendResponse ,
29+ sendResponse : ( response : unknown ) => void ,
4430) : true | undefined {
4531 if ( ! isMessengerMessage ( message ) ) {
4632 // TODO: Add test for this eventuality: ignore unrelated messages
@@ -58,7 +44,14 @@ function onMessageListener(
5844 return ;
5945 }
6046
61- void adaptResponse ( sendResponse , handleMessage ( message , sender , action ) ) ;
47+ ( async ( ) => {
48+ try {
49+ sendResponse ( await handleMessage ( message , sender , action ) ) ;
50+ } catch ( error ) {
51+ sendResponse ( { __webextMessenger : true , error : serializeError ( error ) } ) ;
52+ }
53+ } ) ( ) ;
54+
6255 return true ;
6356}
6457
You can’t perform that action at this time.
0 commit comments