0e524f3e9a
* WIP: detect private browsing and safari blocked cookies * just check for indexeddb * just check for indexeddb * change warning text * change text * change text again * change text again fixes #444
43 lines
928 B
JavaScript
43 lines
928 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 testHasLocalStorage = thunk(() => {
|
|
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 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
|
|
})
|