LocalStorage in chrome Incognito Mode

StrugglingCoder picture StrugglingCoder · Jul 1, 2017 · Viewed 25.8k times · Source

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 localStoarge and it works fine n incognito mode also.

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?

Answer

will picture will · Oct 20, 2020

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.