Detect if access to localStorage is forbidden by the user's browser
If the user's cookie/persistent storage setting forbid access to localStorage, catch the exception and abort the access. Currently, attempting to use the expand/contract links at the top of the page for structs/consts/etc. fails due to an unhandled error while accessing localStorage, if such access is forbidden, as the exception from the failed access propagates all the way out, interrupting the expand/contract. Instead, I would like to degrade gracefully; the access won't happen (the collapse/expand state won't get persisted) but the actual expanding/contracting of the item will go on to succeed. Fixes #55079
This commit is contained in:
parent
14f42a732f
commit
d4e2dcaff1
1 changed files with 6 additions and 0 deletions
|
@ -28,6 +28,12 @@ function onEach(arr, func) {
|
|||
|
||||
function updateLocalStorage(name, value) {
|
||||
if (typeof(Storage) !== "undefined") {
|
||||
try {
|
||||
window.localStorage;
|
||||
} catch(err) {
|
||||
// Storage is supported, but browser preferences deny access to it.
|
||||
return;
|
||||
}
|
||||
localStorage[name] = value;
|
||||
} else {
|
||||
// No Web Storage support so we do nothing
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue