inform when dysfunctional due to FF options

This commit is contained in:
tophf 2017-08-24 16:30:13 +03:00
parent 8525ea9017
commit 8976bd58b8
10 changed files with 102 additions and 8 deletions

View File

@ -135,6 +135,14 @@
"message": "Double-click to maximize/restore the height", "message": "Double-click to maximize/restore the height",
"description": "Tooltip for the resize grip in style editor" "description": "Tooltip for the resize grip in style editor"
}, },
"dysfunctional": {
"message": "Stylus cannot function because Firefox is either in private mode or is applying its website cookies policy to IndexedDB storage used by Stylus, which erroneously marks the secure moz-extension:// origin as insecure even though WebExtensions aren't websites and Stylus doesn't use cookies.\n\n1. Open Firefox options\n2. Go to 'Privacy & Security'\n3. Set 'History' mode to 'Use custom settings'\n4. Click 'Exceptions'\n5. Paste our manifest URL and click 'Allow'\n6. Click 'Save settings'\n7. Uncheck 'Always use private browsing mode'\n\nThe actual manifest URL is shown below.\nYou can also find it on about:debugging page.",
"description": "Displayed in Firefox when its settings make Stylus dysfunctional"
},
"dysfunctionalBackgroundConnection": {
"message": "Cannot function properly because of a known bug in this version of Firefox: chrome.extension.getBackgroundPage() doesn't return a valid result",
"description": "Displayed in style manager when unable to connect to the background page"
},
"genericDisabledLabel": { "genericDisabledLabel": {
"message": "Disabled", "message": "Disabled",
"description": "Used in various lists/options to indicate that something is disabled" "description": "Used in various lists/options to indicate that something is disabled"

View File

@ -5,10 +5,8 @@
var browserCommands, contextMenus; var browserCommands, contextMenus;
// ************************************************************************* // *************************************************************************
// preload the DB and report errors // preload the DB
dbExec().catch((...args) => { tryCatch(getStyles);
args.forEach(arg => 'message' in arg && console.error(arg.message));
});
// ************************************************************************* // *************************************************************************
// register all listeners // register all listeners

View File

@ -59,7 +59,7 @@ function dbExec(method, data) {
} }
}, },
onerror(event) { onerror(event) {
console.warn(event.target.errorCode); console.warn(event.target.error || event.target.errorCode);
reject(event); reject(event);
}, },
onupgradeneeded(event) { onupgradeneeded(event) {

View File

@ -18,7 +18,7 @@ var updater = {
ERROR_MD5: 'error: MD5 is invalid', ERROR_MD5: 'error: MD5 is invalid',
ERROR_JSON: 'error: JSON is invalid', ERROR_JSON: 'error: JSON is invalid',
lastUpdateTime: parseInt(localStorage.lastUpdateTime) || Date.now(), lastUpdateTime: parseInt(tryCatch(() => localStorage.lastUpdateTime)) || Date.now(),
checkAllStyles({observer = () => {}, save = true, ignoreDigest} = {}) { checkAllStyles({observer = () => {}, save = true, ignoreDigest} = {}) {
updater.resetInterval(); updater.resetInterval();

View File

@ -39,6 +39,7 @@ for (const type of [NodeList, NamedNodeMap, HTMLCollection, HTMLAllCollection])
// add favicon in Firefox // add favicon in Firefox
// eslint-disable-next-line no-unused-expressions // eslint-disable-next-line no-unused-expressions
navigator.userAgent.includes('Firefox') && setTimeout(() => { navigator.userAgent.includes('Firefox') && setTimeout(() => {
dieOnDysfunction();
const iconset = ['', 'light/'][prefs.get('iconset')] || ''; const iconset = ['', 'light/'][prefs.get('iconset')] || '';
for (const size of [38, 32, 19, 16]) { for (const size of [38, 32, 19, 16]) {
document.head.appendChild($element({ document.head.appendChild($element({
@ -173,3 +174,29 @@ function retranslateCSS(selectorToMessageMap) {
} }
} }
} }
function dieOnDysfunction() {
function die() {
location.href = '/msgbox/dysfunctional.html';
throw 0;
}
(() => {
try {
return indexedDB;
} catch (e) {
die();
}
})();
Object.assign(indexedDB.open('test'), {
onerror: die,
onupgradeneeded: indexedDB.deleteDatabase('test'),
});
// TODO: fallback to sendMessage in FF since private windows can't get bg page
chrome.windows.getCurrent(wnd => wnd.incognito && die());
// check if privacy settings were fixed but the extension wasn't reloaded
const bg = chrome.extension.getBackgroundPage();
if (bg && !(bg.cachedStyles || {}).list) {
chrome.runtime.reload();
}
}

View File

@ -74,6 +74,9 @@ var prefs = new function Prefs() {
specific: new Map(), specific: new Map(),
}; };
// FF may think localStorage is a cookie or that it's not secure
const localStorage = tryCatch(() => localStorage) ? window.localStorage : {};
// coalesce multiple pref changes in broadcast // coalesce multiple pref changes in broadcast
let broadcastPrefs = {}; let broadcastPrefs = {};
@ -203,7 +206,7 @@ var prefs = new function Prefs() {
} }
}; };
getSync().get('settings', ({settings}) => importFromSync(settings)); getSync().get('settings', ({settings} = {}) => importFromSync(settings));
chrome.storage.onChanged.addListener((changes, area) => { chrome.storage.onChanged.addListener((changes, area) => {
if (area === 'sync' && 'settings' in changes) { if (area === 'sync' && 'settings' in changes) {

View File

@ -35,7 +35,8 @@ Promise.all([
}); });
if (FIREFOX) { if (FIREFOX) {
// TODO: remove when this bug is fixed in FF // TODO: remove when these bugs are fixed in FF
dieOnNullBackground();
retranslateCSS({ retranslateCSS({
'.disabled h2::after': '.disabled h2::after':
'__MSG_genericDisabledLabel__', '__MSG_genericDisabledLabel__',
@ -538,3 +539,24 @@ function usePrefsDuringPageLoad() {
startObserver(); startObserver();
onDOMready().then(() => observer.disconnect()); onDOMready().then(() => observer.disconnect());
} }
function dieOnNullBackground() {
if (BG) {
return;
}
chrome.runtime.sendMessage({method: 'healthCheck'}, health => {
if (health && !chrome.extension.getBackgroundPage()) {
onDOMready().then(() => {
chrome.runtime.sendMessage({method: 'getStyles'}, showStyles);
messageBox({
title: 'Stylus',
className: 'danger center',
contents: t('dysfunctionalBackgroundConnection'),
onshow: () => $('#message-box-close-icon').remove(),
});
document.documentElement.style.pointerEvents = 'none';
});
}
});
}

21
msgbox/dysfunctional.css Normal file
View File

@ -0,0 +1,21 @@
html {
height: 100vh;
min-height: 450px;
display: flex;
align-items: center;
justify-content: center;
white-space: pre-wrap;
background-color: #555;
box-sizing: border-box;
border: 2vw solid black;
}
body {
margin: 2em;
color: white;
max-width: 600px;
}
div {
color: antiquewhite;
}

View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html id="stylus">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="dysfunctional.css">
</head>
<body>
<script src="dysfunctional.js"></script>
</body>

6
msgbox/dysfunctional.js Normal file
View File

@ -0,0 +1,6 @@
'use strict';
document.body.textContent =
chrome.i18n.getMessage('dysfunctional');
document.body.appendChild(document.createElement('div')).textContent =
chrome.runtime.getURL('manifest.json');