Skip to content

Commit

Permalink
better error notification for missing host permission during capture
Browse files Browse the repository at this point in the history
  • Loading branch information
karlicoss committed Apr 22, 2024
1 parent 2e1eb3e commit 957c937
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions extension/src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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}`)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_end2end.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down

0 comments on commit 957c937

Please sign in to comment.