propagate error; work around Firefox fussiness

This commit is contained in:
Dima Gerasimov 2020-02-08 13:59:08 +00:00 committed by Dmitrii Gerasimov
parent f24ca71ba4
commit 87e9bf4127

View file

@ -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???
}