Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,22 +233,25 @@ 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) {
showStatus("optionsPermissionDenied", "instance-status")
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 = ""
Expand Down