From 87e9bf41276613fd1309ef5696c9ff420dcf7169 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Sat, 8 Feb 2020 13:59:08 +0000 Subject: [PATCH] propagate error; work around Firefox fussiness --- src/js/common.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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??? }