pinafore/src/routes/_utils/testStorage.js
Nolan Lawson 4bd181d3cc
fix: update Sapper to latest (#775)
* fix: update to latest sapper

fixes #416

* fix error and debug pages

* requestIdleCallback makes column switching feel way nicer than double rAF

* add export feature

* add better csp info

* workaround for sapper sub-page issue

* clarify in readme about exporting

* fix now config

* switch from rIC to triple raf

* style-loader is no longer used

* update theming guide
2018-12-11 07:31:48 -08:00

45 lines
992 B
JavaScript

// LocalStorage and IDB may be disabled in private mode, when "blocking cookies" in Safari,
// or other cases
import { thunk } from './thunk'
const testKey = '__test__'
export const testHasLocalStorageOnce = () => {
try {
localStorage.setItem(testKey, testKey)
if (!localStorage.length || localStorage.getItem(testKey) !== testKey) {
return false
}
localStorage.removeItem(testKey)
} catch (e) {
return false
}
return true
}
export const testHasLocalStorage = thunk(testHasLocalStorageOnce)
export const testHasIndexedDB = thunk(async () => {
if (typeof indexedDB === 'undefined') {
return false
}
try {
let idbFailed = await new Promise(resolve => {
let db = indexedDB.open(testKey)
db.onerror = () => resolve(true)
db.onsuccess = () => {
indexedDB.deleteDatabase(testKey)
resolve(false)
}
})
if (idbFailed) {
return false
}
} catch (e) {
return false
}
return true
})