-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issue where feature detection for localStorage was incorrectly applied. Due to the different browser configurations and security settings that can involve localStorage, feature detection needs to be placed within a try/catch block.
- Loading branch information
1 parent
0be86b2
commit 5783879
Showing
5 changed files
with
42 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export function storageAvailable(type) { | ||
let storage; | ||
try { | ||
storage = window[type]; | ||
const x = "__storage_test__"; | ||
storage.setItem(x, x); | ||
storage.removeItem(x); | ||
return true; | ||
} catch (e) { | ||
return ( | ||
((e instanceof DOMException && | ||
// everything except Firefox | ||
e.code === 22) || | ||
// Firefox | ||
e.code === 1014 || | ||
// test name field too, because code might not be present | ||
// everything except Firefox | ||
e.name === "QuotaExceededError" || | ||
// Firefox | ||
e.name === "NS_ERROR_DOM_QUOTA_REACHED") && | ||
// acknowledge QuotaExceededError only if there's something already stored | ||
storage && | ||
storage.length !== 0 | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters