fix(permissions): request host permissions during user gesture, not in background
CI / Build & Test (push) Failing after 2m42s
CI / Build & Test (push) Failing after 2m42s
chrome.permissions.request() must be called synchronously within a user gesture. Moving it from the background message-router (where the gesture context has expired) into the addVhostSubmit click handler in virtual-hosts.js fixes the "Unchecked runtime.lastError: This function must be called during a user gesture" console error.
This commit is contained in:
@@ -180,21 +180,41 @@ function setupVirtualHostEvents() {
|
||||
if (!hsUrl || !hsUrl.startsWith('hs://')) { showModalError('modal-addVhost', 'addVhostError', 'Enter a valid hs:// URL'); return; }
|
||||
const btn = $('addVhostSubmit');
|
||||
if (btn) { btn.disabled = true; btn.textContent = 'Adding…'; }
|
||||
chrome.runtime.sendMessage(
|
||||
{ target: 'holesail-native', action: 'send', payload: { type: 'setVirtualHost', payload: { hostname, hsUrl } } },
|
||||
(response) => {
|
||||
if (btn) { btn.disabled = false; btn.textContent = 'Add Host'; }
|
||||
if (response?.ok) {
|
||||
if (hostnameEl) hostnameEl.value = '';
|
||||
if (hsUrlEl) hsUrlEl.value = '';
|
||||
closeModal('modal-addVhost');
|
||||
showToast('Virtual host added', 'success');
|
||||
refresh();
|
||||
} else {
|
||||
showModalError('modal-addVhost', 'addVhostError', response?.error || 'Failed to add');
|
||||
|
||||
function doAddVhost() {
|
||||
chrome.runtime.sendMessage(
|
||||
{ target: 'holesail-native', action: 'send', payload: { type: 'setVirtualHost', payload: { hostname, hsUrl } } },
|
||||
(response) => {
|
||||
if (btn) { btn.disabled = false; btn.textContent = 'Add Host'; }
|
||||
if (response?.ok) {
|
||||
if (hostnameEl) hostnameEl.value = '';
|
||||
if (hsUrlEl) hsUrlEl.value = '';
|
||||
closeModal('modal-addVhost');
|
||||
showToast('Virtual host added', 'success');
|
||||
refresh();
|
||||
} else {
|
||||
showModalError('modal-addVhost', 'addVhostError', response?.error || 'Failed to add');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Request host permissions synchronously within the user gesture so Chrome
|
||||
// allows the permissions.request call. Non-hole.sail custom domains need
|
||||
// explicit host permission for the extension to intercept their traffic.
|
||||
const parts = hostname.split('.');
|
||||
if (parts.length >= 3) {
|
||||
const baseDomain = parts.slice(-2).join('.');
|
||||
if (baseDomain !== 'hole.sail') {
|
||||
const origin = '*://*.' + baseDomain + '/*';
|
||||
chrome.permissions.request({ origins: [origin] }, () => {
|
||||
void chrome.runtime.lastError;
|
||||
doAddVhost();
|
||||
});
|
||||
return;
|
||||
}
|
||||
);
|
||||
}
|
||||
doAddVhost();
|
||||
});
|
||||
|
||||
$('removeVhostConfirm')?.addEventListener('click', () => {
|
||||
|
||||
Reference in New Issue
Block a user