Fixed some traps around Messages abstraction.

This commit is contained in:
hackademix 2020-08-17 21:00:15 +02:00
parent 2850f631b9
commit 5c99ed053b
2 changed files with 7 additions and 5 deletions

View File

@ -100,14 +100,14 @@
}
}
for (;;) {
for (let attempts = 3; attempts-- > 0;) {
try {
browser.runtime.sendSyncMessage(
{id: "fetchPolicy", url, contextUrl: url},
setup);
break;
} catch (e) {
if (!Messages.isMissingEndpoint(e)) {
if (!Messages.isMissingEndpoint(e) || document.readyState === "complete") {
error(e);
break;
}

View File

@ -12,6 +12,8 @@
}
__meta = {name: _messageName};
}
delete msg.__meta;
delete msg._messageName;
let {name} = __meta;
let responderFound = false;
let exception = null;
@ -61,14 +63,14 @@
args._messageName = name; // legacy protocol, for embedders
if (recipientInfo && "tabId" in recipientInfo) {
let opts;
if ("frameId" in recipientInfo) opts = {frameId: recipientInfo.frameId};
return await browser.tabs.sendMessage(recipientInfo.tabId, args, opts);
if ("frameId" in recipientInfo) opts = {frameId: parseInt(recipientInfo.frameId)};
return await browser.tabs.sendMessage(parseInt(recipientInfo.tabId), args, opts);
}
return await browser.runtime.sendMessage(args);
},
isMissingEndpoint(error) {
return error && error.message ===
"Could not esablish connection. Receiving end does not exist.";
"Could not establish connection. Receiving end does not exist.";
}
}
}