From 957c937948a36d12f6f22cb0a08041b9dd54fadb Mon Sep 17 00:00:00 2001 From: karlicoss Date: Mon, 22 Apr 2024 01:31:15 +0100 Subject: [PATCH] better error notification for missing host permission during capture --- extension/src/background.ts | 11 +++++++++++ tests/test_end2end.py | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/extension/src/background.ts b/extension/src/background.ts index 7c1c0de..afa24e2 100644 --- a/extension/src/background.ts +++ b/extension/src/background.ts @@ -33,6 +33,7 @@ import browser from "webextension-polyfill" import {COMMAND_CAPTURE_SIMPLE, METHOD_CAPTURE_WITH_EXTRAS, showNotification} from './common' import {getOptions} from './options' import type {Options} from './options' +import { hasPermissions } from './permissions' type Params = { @@ -54,6 +55,16 @@ async function makeCaptureRequest( const endpoint = options.endpoint + // Ugh. this is kinda idiotic. + // We can't call ensurePermissions here, getting "permissions.request may only be called from a user input handler" error + // even though it's called from the keyboard shortcut??? + // so the best we can do is try to check and at least show a more helful error + + const has = await hasPermissions(endpoint) + if (!has) { + throw new Error(`${endpoint}: no permissions detected! Go to extension settings and approve them.`) + } + const data = JSON.stringify(params) console.log(`capturing ${data} via ${endpoint}`) diff --git a/tests/test_end2end.py b/tests/test_end2end.py index 64cff53..a4df5c8 100644 --- a/tests/test_end2end.py +++ b/tests/test_end2end.py @@ -220,7 +220,7 @@ def confirm(what: str) -> None: # chrome v3 works # firefox v2 works -# firefox v3 BROKEN -- needs the user to approve the localhost access FIXME -- request permission at capture time? +# firefox v3 BROKEN -- needs the user to approve the localhost access def test_capture_no_configuration(addon: Addon) -> None: """ This checks that capture works with default hostname/port without opening settings first @@ -229,7 +229,7 @@ def test_capture_no_configuration(addon: Addon) -> None: # so if it's already running, not sure what to do since we'll have to somehow detect it and extract data from it # (probably a bad idea to try to access it from the test either) - # TODO can we just request Driver object directly? + # todo can we just request Driver object directly? driver = addon.helper.driver driver.get('https://example.com')