locked
Session storage not working - QuotaExceededError

    Question

  • Hi,

    I have a project where I'm using the following code to store some data:

    window.sessionStorage.setItem

    It was working fine and some devices running my app still work, but now I'm trying to make some changes to the project and that code doesn't work any more. I get the following error:

    QuotaExceededError

    Since I couldn't get any info about this error connected to Windows Store Development I changed the code to:

    WinJS.Application.sessionState.MyProperty = MyValue

    That is what I could find regarding session storage reading these articles:

    http://msdn.microsoft.com/en-us/library/windows/apps/hh986966.aspx

    http://msdn.microsoft.com/en-us/library/windows/apps/hh440965.aspx

    But it's not working either. Data added to the sessionState oject is not avaiable when I navigate to another page.

    I'd like to know how I store session data (data that I want avaiable until app closes) and why my first solution worked but doesn't work anymore.


    Thursday, August 7, 2014 3:09 PM

Answers

  • My advice would be to use the WinJS session storage and implement the navigation pattern to ensure session transition between pages, you will probably end up using less time this way (plus you are kind of doing it the "right" way for a Win8 app) than keep on trying or searching the reason behind the Quota on the window.sessionStorage problem.

    Remember that even though an HTML/JS App runs on an environment that resembles IE (same rendering engine), it's not 100% a browser, and maybe that's where the main problem relies.

    • Marked as answer by Mahanstein Monday, October 6, 2014 2:20 PM
    Thursday, August 21, 2014 2:42 PM

All replies

  • Hi Mahanstein,

    MSDN says the data saved in SessionState is automatically serialized to disk when your app is suspended. Please check this scenario. The action will fail only in the scenario which your app crashes or is terminated prior to the completion of the suspension of the app. Are you missing something? Or you can provide a code sample for reproduce, I am going to look into it.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, August 8, 2014 8:30 AM
    Moderator
  • Hi,

    thanks for the response. The code sample is the one I gave in the initial post, a plain setItem in the session, nothing complex. The only new information I have is that I tested the project in another machine and it worked fine. It's like packages suddenly lost permission to save session data in my machine.

    I created a new project with nothing but a call to the sessionState.setItem and it throws the same Quotaexceeded error.

    I guess Its more a windows 8.1 forums question... 


    Friday, August 8, 2014 3:11 PM
  • Hi Mahanstein,

    > I created a new project with nothing but a call to the sessionState.setItem and it throws the same Quotaexceeded error.

    Yes, session data is temporary data that is relevant to the user’s current session in your app. we can use the close gesture or Alt+ F4 to clear the session storage. Did you have tried this? If this doesn’t work, try to reinstall .NET Framework, use the following tool http://www.microsoft.com/en-hk/download/details.aspx?id=30135.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, August 13, 2014 3:18 AM
    Moderator
  • Hi!

    The QuotaExcededError is because you are trying to save data to the Local Storage and you are reaching it's limit. Local Storage has a limit of aproximatelly 10 Mb per origin.

    Depending on what type of data you are handling, you can use Application Data (WinJS.ApplicationData) , the session state (WinJS.Application.sessionState) or a database like IndexedDB.

    Like Herro said, the sessionState is maintained and restored automatically as long as the App doesn't crash or end, if you check the "default.js" file that is created on any Win8 store App you will see that on the "checkpoint" event, the current nav history is stored and on the "activated" event, it's restored.

    app.addEventListener("activated", function (args) {
            if (args.detail.kind === activation.ActivationKind.launch) {
                if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
                    // TODO: This application has been newly launched. Initialize
                    // your application here.
                } else {
                    // TODO: This application has been reactivated from suspension.
                    // Restore application state here.
                }
    
                if (app.sessionState.history) {
                    nav.history = app.sessionState.history;
                }
                args.setPromise(WinJS.UI.processAll().then(function () {
                    if (nav.location) {
                        nav.history.current.initialPlaceholder = true;
                        return nav.navigate(nav.location, nav.state);
                    } else {
                        return nav.navigate(Application.navigator.home);
                    }
                }));
            }
        });
    
    app.oncheckpoint = function (args) {
            // TODO: This application is about to be suspended. Save any state
            // that needs to persist across suspensions here. If you need to 
            // complete an asynchronous operation before your application is 
            // suspended, call args.setPromise().
            app.sessionState.history = nav.history;
        };

    sessionState shouldn't be throwing a QuotaExcededError, are you sure it's not the Local Storage line throwing it?

    I would advice reading also:

    Storing and retrieving state efficiently

    and:

    Accessing app data with the Windows Runtime

    also:

    Manage app lifecycle and state

    • Proposed as answer by Ealsur Sunday, October 5, 2014 4:26 PM
    Thursday, August 14, 2014 4:42 PM
  • Hi, thanks for the response.

    I'm sure the error is with the session storage line because its the only line on the page.

    I tried to use the WinJS sessionState, but its not working either. I set a value like this:

    WinJS.Application.sessionState.something = "something";

    Then I redirect to another page like this:

    window.location = "newpage.html";

    But when I try to recover the value:

    var value = WinJS.Application.sessionState.something;

    It doesnt exists any more.

    Thursday, August 14, 2014 7:50 PM
  • The problem is that you are using window.location to change the page, this is not really a website, an HTML/JS should take advantage of the WinJS framework.

    You either use the Navigation pattern or use WinJS.Navigation.navigate and pass the current session state as a parameter. I would advice the first, since it's the default solution when you create any Win8 app in Visual Studio (by default the empty app template uses this pattern).

    Try creating a new app from scratch using the templates from Visual Studio, it will implement the Nav pattern for you.

    Thursday, August 14, 2014 8:02 PM
  • I'll try this approach, but the original question is about

    window.sessionStorage.setItem

    And how it used to work and doesn't work anymore.

    Monday, August 18, 2014 4:24 PM
  • window.sessionStorage.setItem will not work if you are browsing away from the page with window.location because once you browse away, the session is finished. It does work if you don't navigate away. The QuotaExcededError is because the session storage is full, it does have a max size, and in a Win8 environment, I'm not sure which is it (in normal browser environment it should be between 5-10Mb).

    That's why you can't read the session item value on the next page.

    The best solution is to use the WinJS framework within a Win8 App and the Navigation pattern, it will make your life easier and abstract your code from maintaining the session.

    Tuesday, August 19, 2014 12:32 PM
  • I couldn't find any sample using page to page navigation (like a web site).

    But I found this in the Microsoft Press eBook:

    Programming Windows 8 Apps HTML CSS_JavaScript

    "To compare, many web applications do page-to-page navigation with <a href> hyperlinks or by 
    setting document.location from JavaScript. This is all well and good: oftentimes there’s little or no 
    state to pass between pages, and even then there are well-established mechanisms for doing so, such 
    as HTML5 sessionStorage and localStorage (which work just fine in Store apps, by the way)."

    So to navigate using document.location and the html5 sessionState should work.

    I still want to know how to fix the QuotaExceededError thrown as soon as I try to set a simple string to the sessionStorage.

    Tuesday, August 19, 2014 4:44 PM
  • I'm really sorry, I couldn't find a reason of the Quota Exceeded Error other than the storage being full, maybe you filled it up on previous tests of the App and it doesn't get cleared automatically on each build/deploy.

    Did you try doing a:

    window.sessionStorage.clear();
    when the App is initialized? You can probably hook it up on the "default.js" file in your project, on the "activated" handler.
    Thursday, August 21, 2014 11:53 AM
  • I know! Isn't that weird? There's nothing in the sessionStorage, I clear it anyway, but I still get the quotaExceededError.

    I appreciate the help, I can't find anyone that faced the same problem. Just one guy that appealed to a windows reinstall... I really don't want to do that... 

    I wish I knew where this quota setting is hidden so I can check if it's there.

    Thursday, August 21, 2014 1:06 PM
  • My advice would be to use the WinJS session storage and implement the navigation pattern to ensure session transition between pages, you will probably end up using less time this way (plus you are kind of doing it the "right" way for a Win8 app) than keep on trying or searching the reason behind the Quota on the window.sessionStorage problem.

    Remember that even though an HTML/JS App runs on an environment that resembles IE (same rendering engine), it's not 100% a browser, and maybe that's where the main problem relies.

    • Marked as answer by Mahanstein Monday, October 6, 2014 2:20 PM
    Thursday, August 21, 2014 2:42 PM