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 {
|
try {
|
||||||
browser.runtime.sendSyncMessage(
|
browser.runtime.sendSyncMessage(
|
||||||
{id: "fetchPolicy", url, contextUrl: url},
|
{id: "fetchPolicy", url, contextUrl: url},
|
||||||
setup);
|
setup);
|
||||||
break;
|
break;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!Messages.isMissingEndpoint(e)) {
|
if (!Messages.isMissingEndpoint(e) || document.readyState === "complete") {
|
||||||
error(e);
|
error(e);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
}
|
}
|
||||||
__meta = {name: _messageName};
|
__meta = {name: _messageName};
|
||||||
}
|
}
|
||||||
|
delete msg.__meta;
|
||||||
|
delete msg._messageName;
|
||||||
let {name} = __meta;
|
let {name} = __meta;
|
||||||
let responderFound = false;
|
let responderFound = false;
|
||||||
let exception = null;
|
let exception = null;
|
||||||
|
@ -61,14 +63,14 @@
|
||||||
args._messageName = name; // legacy protocol, for embedders
|
args._messageName = name; // legacy protocol, for embedders
|
||||||
if (recipientInfo && "tabId" in recipientInfo) {
|
if (recipientInfo && "tabId" in recipientInfo) {
|
||||||
let opts;
|
let opts;
|
||||||
if ("frameId" in recipientInfo) opts = {frameId: recipientInfo.frameId};
|
if ("frameId" in recipientInfo) opts = {frameId: parseInt(recipientInfo.frameId)};
|
||||||
return await browser.tabs.sendMessage(recipientInfo.tabId, args, opts);
|
return await browser.tabs.sendMessage(parseInt(recipientInfo.tabId), args, opts);
|
||||||
}
|
}
|
||||||
return await browser.runtime.sendMessage(args);
|
return await browser.runtime.sendMessage(args);
|
||||||
},
|
},
|
||||||
isMissingEndpoint(error) {
|
isMissingEndpoint(error) {
|
||||||
return error && error.message ===
|
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