summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bg/RequestUtil.js9
-rw-r--r--src/content/content.js9
2 files changed, 15 insertions, 3 deletions
diff --git a/src/bg/RequestUtil.js b/src/bg/RequestUtil.js
index b0fa913..659fd33 100644
--- a/src/bg/RequestUtil.js
+++ b/src/bg/RequestUtil.js
@@ -30,7 +30,14 @@
frameId,
}, details);
try {
- await browser.tabs.executeScript(tabId, details);
+ for (let attempts = 10; attempts-- > 0;) {
+ try {
+ await browser.tabs.executeScript(tabId, details);
+ } catch(e) {
+ if (!/No matching message handler/.test(e.message)) throw e;
+ debug("Couldn't inject script into %s: too early? Retrying up to %s times...", url, attempts);
+ }
+ }
count++;
debug("Execute on start OK", url, details);
} catch (e) {
diff --git a/src/content/content.js b/src/content/content.js
index fa87ba8..daca1c3 100644
--- a/src/content/content.js
+++ b/src/content/content.js
@@ -85,8 +85,13 @@ async function init() {
debug("canScript:", canScript);
} catch (e) {
debug("Error querying canScript", e);
- // background script not initialized yet?
- setTimeout(() => init(), 100);
+ if (document.readyState !== "complete" &&
+ document.URL !== "about:blank" &&
+ /Receiving end does not exist/.test(e.message)) {
+ window.location.reload(false);
+ } else {
+ setTimeout(() => init(), 100);
+ }
return;
} finally {
queryingCanScript = false;