Skip to content

Commit 2c2d0a1

Browse files
committed
updating from master
2 parents 9e9eff0 + a7fd07b commit 2c2d0a1

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Unreleased
22

33
* Add support for passing callback function to init.
4+
* Fix bug to check that Window localStorage is available for use.
45

56
## 2.4.0 (September 4, 2015)
67

amplitude.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,22 @@ module.exports = {
15761576
*/
15771577
var localStorage; // jshint ignore:line
15781578

1579-
if (window.localStorage) {
1579+
// test that Window.localStorage is available and works
1580+
function windowLocalStorageAvailable() {
1581+
var uid = new Date();
1582+
var result;
1583+
try {
1584+
window.localStorage.setItem(uid, uid);
1585+
result = window.localStorage.getItem(uid) === String(uid);
1586+
window.localStorage.removeItem(uid);
1587+
return result;
1588+
} catch (e) {
1589+
// localStorage not available
1590+
}
1591+
return false;
1592+
}
1593+
1594+
if (windowLocalStorageAvailable()) {
15801595
localStorage = window.localStorage;
15811596
} else if (window.globalStorage) {
15821597
// Firefox 2-3 use globalStorage

amplitude.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/localstorage.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,22 @@
55
*/
66
var localStorage; // jshint ignore:line
77

8-
if (window.localStorage) {
8+
// test that Window.localStorage is available and works
9+
function windowLocalStorageAvailable() {
10+
var uid = new Date();
11+
var result;
12+
try {
13+
window.localStorage.setItem(uid, uid);
14+
result = window.localStorage.getItem(uid) === String(uid);
15+
window.localStorage.removeItem(uid);
16+
return result;
17+
} catch (e) {
18+
// localStorage not available
19+
}
20+
return false;
21+
}
22+
23+
if (windowLocalStorageAvailable()) {
924
localStorage = window.localStorage;
1025
} else if (window.globalStorage) {
1126
// Firefox 2-3 use globalStorage

0 commit comments

Comments
 (0)