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,17 +1319,26 @@ class Display extends EventDispatcher {
}
_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);
}
_setMode(mode, save) {
if (mode === this._mode) { return; }
if (save) {
if (mode === null) {
sessionStorage.removeItem('mode');
} else {
sessionStorage.setItem('mode', mode);
try {
if (mode === null) {
sessionStorage.removeItem('mode');
} else {
sessionStorage.setItem('mode', mode);
}
} catch (e) {
// Browsers can throw a SecurityError when cookie blocking is enabled.
}
}
this._mode = mode;