Skip to content

Commit

Permalink
[Chromium] Fixed no permissions given on first page load in a session.
Browse files Browse the repository at this point in the history
  • Loading branch information
hackademix committed Dec 23, 2019
1 parent 08f2509 commit 1b8d1c7
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/lib/SyncMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1b8d1c7

Please sign in to comment.