MCPcopy Create free account
hub / github.com/ClearURLs/Addon / sendPromisedResult

Function sendPromisedResult

browser-polyfill.js:1096–1117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1094 // to translate the message into a resolved promise or a rejected
1095 // promise).
1096 const sendPromisedResult = promise => {
1097 promise.then(msg => {
1098 // send the message value.
1099 sendResponse(msg);
1100 }, error => {
1101 // Send a JSON representation of the error if the rejected value
1102 // is an instance of error, or the object itself otherwise.
1103 let message;
1104 if (error && (error instanceof Error || typeof error.message === "string")) {
1105 message = error.message;
1106 } else {
1107 message = "An unexpected error occurred";
1108 }
1109 sendResponse({
1110 __mozWebExtensionPolyfillReject__: true,
1111 message
1112 });
1113 }).catch(err => {
1114 // Print an error on the console if unable to send the response.
1115 console.error("Failed to send onMessage rejected reply", err);
1116 });
1117 };
1118
1119 // If the listener returned a Promise, send the resolved value as a
1120 // result, otherwise wait the promise related to the wrappedSendResponse

Callers 1

wrapAPIsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected