Skip to content

Commit

Permalink
Add several comments for explaining the behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
nachtjasmin committed Jun 2, 2023
1 parent bed3eb0 commit 4363df0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ async function restoreOptions() {
let getting = storage.sync.get("logging");
getting.then(setCurrentChoice, onError);

// Because we cannot use await/async, we fetch the current tab URL on startup and persist it
// inside a hidden <input>, just so that we can access it synchronously in the submit event.
const u = await getCurrentTabURL();
currentOriginPatternEl.value = `${u.origin}/*`; // we MUST end it with a asterisk for pattern matching

// Query the permissions for the current page. If we don't have them, ask for them.
const hasPermissions = await permissions.contains(getPermissionsForCurrentPage());
manifestPermissionForm.style.display = hasPermissions ? "none" : "block";
}
Expand All @@ -41,6 +44,9 @@ document.querySelector("#resetbutton").addEventListener("click", async () => {
});

manifestPermissionForm.addEventListener("submit", () =>
// WARNING: Whatever you do, do NOT, I repeat, use await/async here.
// If you do that, the request of permissions is going to fail.
// https://bugzilla.mozilla.org/show_bug.cgi?id=1398833
permissions
.request(getPermissionsForCurrentPage())
.then(getCurrentTabID)
Expand Down

0 comments on commit 4363df0

Please sign in to comment.