summaryrefslogtreecommitdiff
path: root/src/content
diff options
context:
space:
mode:
authorhackademix2018-07-22 19:14:54 +0200
committerhackademix2018-07-22 19:14:54 +0200
commit4302246ac01d7dc56650ffa227ad87fe98ccfc03 (patch)
tree2801d4334efecae9885dc3d4a9fcb4056be7a019 /src/content
parent81b38512568982267b48f6df4ae15fb35ef1cc15 (diff)
downloadnoscript-4302246ac01d7dc56650ffa227ad87fe98ccfc03.tar.gz
noscript-4302246ac01d7dc56650ffa227ad87fe98ccfc03.tar.xz
noscript-4302246ac01d7dc56650ffa227ad87fe98ccfc03.zip
More reliable handling of edge startup cases.
Diffstat (limited to 'src/content')
-rw-r--r--src/content/content.js29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/content/content.js b/src/content/content.js
index daca1c3..a183117 100644
--- a/src/content/content.js
+++ b/src/content/content.js
@@ -6,6 +6,18 @@ function createHTMLElement(name) {
return document.createElementNS("http://www.w3.org/1999/xhtml", name);
}
+function probe() {
+ try {
+ debug("Probing execution...");
+ let s = document.createElement("script");
+ s.textContent=";";
+ document.documentElement.appendChild(s);
+ s.remove();
+ } catch(e) {
+ debug(e);
+ }
+}
+
var _ = browser.i18n.getMessage;
var canScript = true;
@@ -62,8 +74,9 @@ if (document.readyState !== "complete") {
init();
};
addEventListener("pageshow", pageshown);
-} else init();
-
+} else {
+ init(true);
+}
let notifyPage = () => {
if (document.readyState === "complete") {
browser.runtime.sendMessage({type: "pageshow", seen, canScript});
@@ -73,24 +86,28 @@ let notifyPage = () => {
}
var queryingCanScript = false;
-async function init() {
+async function init(oldPage = false) {
if (queryingCanScript) return;
queryingCanScript = true;
debug(`NoScript init() called in document %s, scripting=%s, content type %s readyState %s`,
document.URL, canScript, document.contentType, document.readyState);
try {
- canScript = await browser.runtime.sendMessage({type: "canScript"});
+ canScript = document.URL === "about:blank" || await browser.runtime.sendMessage({type: "canScript"});
+ if (oldPage && canScript) {
+ probe();
+ setTimeout(() => init(), 100);
+ return;
+ }
init = () => {};
debug("canScript:", canScript);
} catch (e) {
debug("Error querying canScript", e);
if (document.readyState !== "complete" &&
- document.URL !== "about:blank" &&
/Receiving end does not exist/.test(e.message)) {
window.location.reload(false);
} else {
- setTimeout(() => init(), 100);
+ setTimeout(() => init(oldPage), 100);
}
return;
} finally {