Fix sessionStorage not being supported when cookies are disabled (#756)

* Fix sessionStorage not being supported when cookies are disabled

* Update comment
This commit is contained in:
toasted-nutbread 2020-08-24 18:26:04 -04:00 committed by GitHub
parent 6e31f24ed1
commit bbfe5f81cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1319,18 +1319,27 @@ class Display extends EventDispatcher {
} }
_updateMode() { _updateMode() {
const mode = sessionStorage.getItem('mode'); let mode = null;
try {
mode = sessionStorage.getItem('mode');
} catch (e) {
// Browsers can throw a SecurityError when cookie blocking is enabled.
}
this._setMode(mode, false); this._setMode(mode, false);
} }
_setMode(mode, save) { _setMode(mode, save) {
if (mode === this._mode) { return; } if (mode === this._mode) { return; }
if (save) { if (save) {
try {
if (mode === null) { if (mode === null) {
sessionStorage.removeItem('mode'); sessionStorage.removeItem('mode');
} else { } else {
sessionStorage.setItem('mode', mode); sessionStorage.setItem('mode', mode);
} }
} catch (e) {
// Browsers can throw a SecurityError when cookie blocking is enabled.
}
} }
this._mode = mode; this._mode = mode;
this.trigger('modeChange', {mode}); this.trigger('modeChange', {mode});