diff options
author | hackademix | 2019-12-23 23:34:22 +0100 |
---|---|---|
committer | hackademix | 2019-12-23 23:34:22 +0100 |
commit | 1b8d1c784c0698905660ddd5bfa5f5c856a429e4 (patch) | |
tree | c6407c86902f812394a198d3cd2eb752a771ff2d /src/lib | |
parent | 08f25091e84b50553b80d9f659417e8d26b37866 (diff) | |
download | noscript-1b8d1c784c0698905660ddd5bfa5f5c856a429e4.tar.gz noscript-1b8d1c784c0698905660ddd5bfa5f5c856a429e4.tar.xz noscript-1b8d1c784c0698905660ddd5bfa5f5c856a429e4.zip |
[Chromium] Fixed no permissions given on first page load in a session.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/SyncMessage.js | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/src/lib/SyncMessage.js b/src/lib/SyncMessage.js index b622afe..c889b2c 100644 --- a/src/lib/SyncMessage.js +++ b/src/lib/SyncMessage.js @@ -252,12 +252,35 @@ url += `&msg=${encodeURIComponent(JSON.stringify(msg))}`; // adding the payload let r = new XMLHttpRequest(); let result; - try { - r.open("GET", url, false); - r.send(null); - result = JSON.parse(r.responseText); - } catch(e) { - console.error(`syncMessage error in ${document.URL}: ${e.message} (response ${r.responseText})`); + let key = `${ENDPOINT_PREFIX}`; + let reloaded = sessionStorage.getItem(key) === "reloaded"; + if (reloaded) { + sessionStorage.removeItem(key); + console.log("Syncmessage attempt aftert reloading page."); + } + for (let attempts = 3; attempts-- > 0;) { + try { + r.open("GET", url, false); + r.send(null); + result = JSON.parse(r.responseText); + break; + } catch(e) { + console.error(`syncMessage error in ${document.URL}: ${e.message} (response ${r.responseText}, remaining attempts ${attempts})`); + if (attempts === 0) { + if (reloaded) { + console.log("Already reloaded, giving up.") + break; + } + sessionStorage.setItem(key, "reloaded"); + if (sessionStorage.getItem(key)) { + stop(); + location.reload(); + return {}; + } else { + console.error(`Cannot set sessionStorage item ${key}`); + } + } + } } if (callback) callback(result); return result; |