From 85b8357ce91f4d35bfd522a56c2f353cc06da820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Magimel?= Date: Thu, 9 Jul 2026 07:43:13 +0000 Subject: [PATCH] fix(options): request the host permission before reading storage For self-hosted instances, the permission request was asked too early: the handler called `loadInstances` first, then read `storage.local` which consumed the activation, so the request was no longer "inside" the click. A reordering has been done to keep the grant. Ref #33 --- options/options.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/options/options.js b/options/options.js index 5b7470f..30de122 100644 --- a/options/options.js +++ b/options/options.js @@ -233,15 +233,11 @@ async function addInstance() { } try { - const instances = await loadInstances() - - if (instances.some(i => i.hostname === hostname)) { - showStatus("optionsInstanceExists", "instance-status") - return - } - // the extension may only call the queried API (the review server for - // a Gerrit instance) once the user grants access to its origin + // a Gerrit instance) once the user grants access to its origin. + // permissions.request() must run before any other await, or it loses + // the click's user-activation context and the browser rejects it; an + // already-granted host (the duplicate case) resolves without a prompt. const granted = await browser.permissions.request( { origins: [`*://${permissionHostname(instance)}/*`] }) if (!granted) { @@ -249,6 +245,13 @@ async function addInstance() { return } + const instances = await loadInstances() + + if (instances.some(i => i.hostname === hostname)) { + showStatus("optionsInstanceExists", "instance-status") + return + } + instances.push(instance) await saveInstances(instances) document.getElementById("instance-hostname").value = ""