diff --git a/src/js/common.js b/src/js/common.js index 68e0b58..e3a3ce7 100644 --- a/src/js/common.js +++ b/src/js/common.js @@ -40,6 +40,17 @@ export function chromePermissionsContains(params: any) { } +function urlForPermissionsCheck(url: string): string { + var u = new URL(url); + + u.port = ''; + // firefox doesn't like port numbers + // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Match_patterns#Invalid_match_patterns + + // also toString adds a trailing slash, otherwise Firefox is also confused + return u.toString(); +} + // TODO fuck. doesn't seem to work for Firefox at all... // just getting Error: "An unexpected error occurred" background.bundle.js // seems like this bug https://bugzilla.mozilla.org/show_bug.cgi?id=1382953 @@ -50,8 +61,9 @@ export function ensurePermissions(cb: () => void) { const endpoint = opts.endpoint; // that's capable of handling default (localhost), so shouldn't prompt const perms = { + // TODO shit ok, apparently needs to end with / ?? origins: [ - endpoint, + urlForPermissionsCheck(endpoint), ], }; return chromePermissionsContains(perms).then(has => { @@ -71,6 +83,10 @@ export function ensurePermissions(cb: () => void) { const msg = err ? String(err) : 'Permission was refused'; showNotification(`ERROR: ${msg}`); } + }).catch(err => { + // TODO eh, use generic defensify instead... + console.error(err); + showNotification(`ERROR: ${err}`); }); // TODO improve message somehow??? }