'LocalStorage in chrome Incognito Mode

So In my Angular 1.5 application, I want to retain data on page load also,

So I am using $window.localStorage.

I am reading some value from localStorage and it also works fine in incognito mode.

The page refreshes and yet the values are retained.

if($window.localStorage.selectedServers !== undefined)
    selectedObj = JSON.parse($window.localStorage.selectedServers);

The problem is

When I copy the Url and open in a new tab incognito itself,

The localStorage gets undefined.

How to get rid of this issue? Or what am I doing wrong?



Solution 1:[1]

When I copy the Url and open in a new tab incognito itself,

The localStorage gets undefined.

This is because as mentioned in the comments, incognito / private browsing windows will not retain local / session storage. Therefore when you open a new tab they are empty.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 will