How to store and retrieve window state?
<p>I'm trying to write functions for storing and retrieving window state but cannot figure out how to do that. The idea is that user could make at any time a "snapshot" of the screen and with next login to the app he could retrieve it back, also he can store as many snapshots as he want.
For example: on the page I have 4 different closed panels with some kind of filters and 6 different tabs with grid inside (by default the first tab is opened). Now let's say, I have opened 2 of 4 panels, set some filters and worked with 5th tab. I want to be able to store whole window state (For example "My state 1"), and when I logged in at next time, just choose "My state 1" and get back my window state.
I already store and retrieve all grid properties in DB with next functions: </p>

<p>Store: </p>

<pre><code> $scope.state = {}
 $scope.saveStateString = function(store) {
        $scope.state = JSON.stringify($scope.gridApi.saveState.save(store));
        // console.log("function save state string")
   };
</code></pre>

<p>Retrieve</p>

<pre><code>    if(objNode.folderId){
       eventService.singleFilter(nodeId)
             .then(function (res) {
                   if (res.body){
       $scope.restoreStateString(JSON.parse(res.body));
              }
           });
        }
   else if (typeof objNode.folderId === "undefined"){
         return false
    }

   $scope.restoreStateString = function(restore) {
         $scope.gridApi.saveState.restore( $scope, restore );
     };
</code></pre>

<p>For now I'm trying to store window state in localstorage and do next: </p>

<pre><code> var storeValue = null;
        var keyName = null;
        var _window = {};


        $scope.storeWorkspace = function (){

            for (prop in window)
                _window[prop] = window[prop];

            storeValue = JSON.stringify(_window)

            keyName = prompt("put your key name");
            localStorage.setItem(keyName, storeValue);
        };
</code></pre>

<p>but I get this error </p>

<blockquote>
  <p>angular.js:13708 TypeError: Converting circular structure to JSON
      at Object.stringify (native)</p>
</blockquote>

<p>I clearly understand, why I'm getting this error, it cause JSON doesn't accept circular objects - objects which reference themselves also I see from 
<code>console.log(_window)</code> how the "window" has many objects inside, so I decided to ask:
How to store and retrieve window state? </p>