Skip to content

Commit 3114bfd

Browse files
committed
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
1 parent d56b7c8 commit 3114bfd

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

‎options/options.js‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,22 +233,25 @@ async function addInstance() {
233233
}
234234

235235
try {
236-
const instances = await loadInstances()
237-
238-
if (instances.some(i => i.hostname === hostname)) {
239-
showStatus("optionsInstanceExists", "instance-status")
240-
return
241-
}
242-
243236
// the extension may only call the queried API (the review server for
244-
// a Gerrit instance) once the user grants access to its origin
237+
// a Gerrit instance) once the user grants access to its origin.
238+
// permissions.request() must run before any other await, or it loses
239+
// the click's user-activation context and the browser rejects it; an
240+
// already-granted host (the duplicate case) resolves without a prompt.
245241
const granted = await browser.permissions.request(
246242
{ origins: [`*://${permissionHostname(instance)}/*`] })
247243
if (!granted) {
248244
showStatus("optionsPermissionDenied", "instance-status")
249245
return
250246
}
251247

248+
const instances = await loadInstances()
249+
250+
if (instances.some(i => i.hostname === hostname)) {
251+
showStatus("optionsInstanceExists", "instance-status")
252+
return
253+
}
254+
252255
instances.push(instance)
253256
await saveInstances(instances)
254257
document.getElementById("instance-hostname").value = ""

0 commit comments

Comments
 (0)