Ensure non-available localStorage fails gracefully (#6837)

This commit is contained in:
Jaco 2022-01-17 09:28:21 +01:00 committed by GitHub
parent 919c559ad7
commit 8bcd0e8d30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,7 +40,9 @@ export function createCustom (t: TFunction): LinkOption[] {
export function createOwn (t: TFunction): LinkOption[] {
try {
// this may not be available, e.g. when running via script
const storedItems = localStorage?.getItem(CUSTOM_ENDPOINT_KEY);
const storedItems = typeof localStorage === 'object' && typeof localStorage.getItem === 'function'
? localStorage.getItem(CUSTOM_ENDPOINT_KEY)
: null;
if (storedItems) {
const items = JSON.parse(storedItems) as string[];