Skip to content

Commit

Permalink
Add proper test for detecting unusable storage on iOS in Private Mode
Browse files Browse the repository at this point in the history
Fixes #49
  • Loading branch information
Acconut committed Dec 3, 2016
1 parent 2889872 commit dfe32c8
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
12 changes: 8 additions & 4 deletions dist/tus.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/tus.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/tus.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/tus.min.js.map

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions lib.es5/browser/storage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions lib/browser/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
let hasStorage = false;
try {
hasStorage = "localStorage" in window;
// Attempt to access localStorage
localStorage.length;

// Attempt to store and read entries from the local storage to detect Private
// Mode on Safari on iOS (see #49)
var key = "tusSupport";
localStorage.setItem(key, localStorage.getItem(key));

} catch (e) {
// If we try to access localStorage inside a sandboxed iframe, a SecurityError
// is thrown.
if (e.code === e.SECURITY_ERR) {
// is thrown. When in private mode on iOS Safari, a QuotaExceededError is
// thrown (see #49)
if (e.code === e.SECURITY_ERR || e.code === e.QUOTA_EXCEEDED_ERR) {
hasStorage = false;
} else {
throw e;
Expand Down

0 comments on commit dfe32c8

Please sign in to comment.