1. #1
    Sencha User
    Join Date
    May 2012
    Posts
    4
    Vote Rating
    0
    frecciadelsud836 is on a distinguished road

      0  

    Default Unanswered: Application using localStorage with browser in incognito mode issue

    Unanswered: Application using localStorage with browser in incognito mode issue


    I'm using Sencha Touch 2 to build my mobile website version.

    I've got an issue when browsing in Incognito Mode with Iphone Safari Mobile, Android native Browser and Android and Iphone Chrome.

    In my App i've defined a store for users

    Code:
    Ext.define('MyApp.store.UserLogin', {
        extend: 'Ext.data.Store',
        xtype:'userstore',
        config: {
            model: 'MyApp.model.UserForLogin'
        },
    })
    that uses a model with localStorage proxy:

    Code:
    Ext.define('MyApp.model.UserForLogin', {
        extend: 'Ext.data.Model',
        id: 'model-user',
        config: {
            identifier: 'uuid' ,
            fields: ['myUserField1', 'myUserField2'],
            proxy: {
                type: 'localstorage',
                id  : 'my-local-storage-id'
            },
        }
    });

    and, in my application definition and launcher:

    Code:
    Ext.application({
        name: 'MyApp',
    
    
        models: [
            'UserForLogin'
        ],
        
        stores: [
             'UserLogin'
        ],
    
    
        views: ['Main'],
        controllers: ['Home'],
    
    
        launch: function() {
            Ext.Viewport.add( Ext.create('MyApp.view.Main'));
        }
    })

    When i open my application in normal mode, i can read / write user data using the store, but when i set Incognito (anonymous) mode in mobile browser, application throw this exception on startup:

    QUOTA_EXCEEDED_ERR: DOM Exception 22: An attempt was made to add something to storage that exceeded the quota.

    I read somewhere that max quota for local storage is 5MB, but, when i try to write something in local storage, it's every something less than 10k.

    Sorry for my poor english....! My idea is to add store and model only if localStorage is supported, so i would like to check this somewhere...before main application definition, but i really don't know where..!

    Any Help / Suggestion would be appreciate. Thanks You

  2. #2
    Sencha Premium Member
    Join Date
    Jan 2011
    Location
    Dundas, Ontario, Canada
    Posts
    82
    Vote Rating
    -4
    rgporter can only hope to improve

      0  

    Default


    I have this problem too, it basically prevents the app from loading at all in private mode.

  3. #3
    Sencha User
    Join Date
    May 2012
    Posts
    4
    Vote Rating
    0
    frecciadelsud836 is on a distinguished road

      0  

    Default


    my "bad" solution was this:

    Code:
    proxy: {
                type: (function() { 
                    try {
                        var mod= 'MyApp-Test-LocalStorage';
                        localStorage.setItem(mod, mod);
                        localStorage.removeItem(mod); return true;
                        } catch(e) {
                            return false; 
                        }
                    }()) ? 'localstorage' : 'memory',
                id  : 'MyApp-Logged-User'
            }
    but i would prefer something better than this... Work in Progress...

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,399
    Answers
    3549
    Vote Rating
    849
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    This is the same as private browsing in Safari to which we have an open internal bug reported by myself.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  5. #5
    Sencha User
    Join Date
    May 2012
    Posts
    4
    Vote Rating
    0
    frecciadelsud836 is on a distinguished road

      0  

    Default


    Thank You mitchellsimoens, I intercept Safari Bug with... try...catch ... Greetings from Roma!

  6. #6
    Sencha User
    Join Date
    May 2012
    Posts
    4
    Vote Rating
    0
    Alex Nazarov is on a distinguished road

      0  

    Default


    My solution:
    Code:
    checkPrivateMode: function(){
        var storage,
          fail,
          uid;
        try {
          uid = new Date;
          (storage = window.localStorage).setItem(uid, uid);
          fail = storage.getItem(uid) != uid;
          storage.removeItem(uid);
          fail && (storage = false);
        } catch(e) {
          storage = false;
        }
        if (Ext.os.is.iOS && storage === false) {
          //private mode
        }
      }