Index: polyfill.js |
=================================================================== |
--- a/polyfill.js |
+++ b/polyfill.js |
@@ -38,16 +38,24 @@ |
"tabs.sendMessage", |
"tabs.update", |
"webNavigation.getAllFrames", |
"webRequest.handlerBehaviorChanged", |
"windows.create", |
"windows.update" |
]; |
+ // Since we add a callback for all messaging API calls in our wrappers, |
+ // Chrome assumes we're interested in the response; when there's no response, |
+ // it sets runtime.lastError |
+ const portClosedBeforeResponseError = |
+ // Older versions of Chrome have a typo: |
+ // https://crrev.com/c33f51726eacdcc1a487b21a13611f7eab580d6d |
+ /^The message port closed before a res?ponse was received\.$/; |
+ |
function wrapAPI(api) |
{ |
let object = browser; |
let path = api.split("."); |
let name = path.pop(); |
for (let node of path) |
{ |
@@ -73,17 +81,17 @@ |
if (typeof args[args.length - 1] == "undefined") |
args.pop(); |
return new Promise((resolve, reject) => |
{ |
func.call(object, ...args, result => |
{ |
let error = browser.runtime.lastError; |
- if (error) |
+ if (error && !portClosedBeforeResponseError.test(error.message)) |
{ |
// runtime.lastError is already an Error instance on Edge, while on |
// Chrome it is a plain object with only a message property. |
if (!(error instanceof Error)) |
{ |
error = new Error(error.message); |
// Add a more helpful stack trace. |