Skip to content

Commit

Permalink
fix: check when localStorage is available
Browse files Browse the repository at this point in the history
* Fixes issue #202
if local sotrage is not available it will fallback

* fix: check all accessed values for possbile null first
  • Loading branch information
szwenni committed Aug 8, 2023
1 parent aa2de9e commit e4e84fe
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/script.ts
Expand Up @@ -6,7 +6,7 @@

const knownColorSchemes = ['dark', 'light']

const preference = window.localStorage.getItem('<%= options.storageKey %>') || '<%= options.preference %>'
const preference = (window && window.localStorage && window.localStorage.getItem && window.localStorage.getItem('<%= options.storageKey %>')) || '<%= options.preference %>'
let value = preference === 'system' ? getColorScheme() : preference
// Applied forced color mode
const forcedColorMode = de.getAttribute('data-color-mode-forced')
Expand Down

0 comments on commit e4e84fe

Please sign in to comment.