Skip to content

Commit

Permalink
Store: Don't register web storage in Safari Private Browsing mode. Fixes
Browse files Browse the repository at this point in the history
 #59 - amplify.store quota exceeded safari 5.1.5 private browsing.
  • Loading branch information
scottgonzalez committed May 25, 2012
1 parent 36adbca commit a1f4517
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions store/amplify.store.js
Expand Up @@ -112,11 +112,14 @@ function createFromStorageInterface( storageType, storage ) {
// localStorage + sessionStorage
// IE 8+, Firefox 3.5+, Safari 4+, Chrome 4+, Opera 10.5+, iPhone 2+, Android 2+
for ( var webStorageType in { localStorage: 1, sessionStorage: 1 } ) {
// try/catch for file protocol in Firefox
// try/catch for file protocol in Firefox and Private Browsing in Safari 5
try {
if ( window[ webStorageType ].getItem ) {
createFromStorageInterface( webStorageType, window[ webStorageType ] );
}
// Safari 5 in Private Browsing mode exposes localStorage
// but doesn't allow storing data, so we attempt to store and remove an item.
// This will unfortunately give us a false negative if we're at the limit.
window[ webStorageType ].setItem( "__amplify__", "x" );
window[ webStorageType ].removeItem( "__amplify__" );
createFromStorageInterface( webStorageType, window[ webStorageType ] );
} catch( e ) {}
}

Expand Down

7 comments on commit a1f4517

@nayab9
Copy link

@nayab9 nayab9 commented on a1f4517 Jul 2, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

I recently hit this same issue on the BlackBerry PlayBook browser. When it private browsing, "amplify.store quota exceeded". Switch back to normal browsing, no error is thrown.

Cheers,
Ben

@scottgonzalez
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nayab9 Does this fix it for PlayBook or are you saying that you still see a problem even after this fix?

@nayab9
Copy link

@nayab9 nayab9 commented on a1f4517 Jul 3, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, i was just commenting I saw the same thing on PlayBook, I'm using the v1.1.0 download from the website; should I try a newer version to see if it is fixed?

@scottgonzalez
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please test against master and let me know if it's fixed for you. Thanks.

@obihill
Copy link

@obihill obihill commented on a1f4517 May 4, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have this problem (amplify.store quota exceeded) on first-generation iPad 1. I'm using only sessionStorage. I'm using AmplifyJS Store 1.1.0.

@Dakuan
Copy link

@Dakuan Dakuan commented on a1f4517 Nov 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error still occurs in private browsing on both desktop and mobile safari

@obihill
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I sorted this out a while back.

It appears that when you reset the stored value to null before setting it again, the problem is solved.

amplify.store.sessionStorage( string key, null);
amplify.store.sessionStorage( string key, mixed value);

Cheers.

Please sign in to comment.