Index: ext/content.js |
=================================================================== |
--- a/ext/content.js |
+++ b/ext/content.js |
@@ -74,18 +74,26 @@ |
payload: message |
}); |
+ let resolvePromise = null; |
saroyanm
2018/03/05 20:28:33
I noticed that it took me longer than needed to im
Thomas Greiner
2018/03/06 13:08:47
We're not handling errors yet so we don't need to
|
+ let callbackWrapper = event => |
+ { |
+ if (event.data.type == "response" && event.data.messageId == messageId) |
+ { |
+ window.removeEventListener("message", callbackWrapper); |
+ resolvePromise(event.data.payload); |
+ } |
+ }; |
+ window.addEventListener("message", callbackWrapper); |
if (responseCallback) |
{ |
- let callbackWrapper = event => |
+ resolvePromise = responseCallback; |
+ } |
+ else |
+ { |
+ return new Promise((resolve, reject) => |
{ |
- if (event.data.type == "response" && event.data.messageId == messageId) |
- { |
- window.removeEventListener("message", callbackWrapper); |
- responseCallback(event.data.payload); |
- } |
- }; |
- |
- window.addEventListener("message", callbackWrapper); |
+ resolvePromise = resolve; |
+ }); |
} |
}; |
}()); |