Fixed some traps around Messages abstraction.
This commit is contained in:
parent
2850f631b9
commit
5c99ed053b
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue