Unable To Access Localstorage In Second Tab When Opened In Incognito [mozilla Firefox]
Solution 1:
Check out PersistJS
.
PersistJS is a JavaScript client-side persistent storage library.
One more reasonable thing you could do would be to use some form of a database to store your data in.
Got this directly from HTMLUI Fact #3
LocalStorage values created in "incognito" mode are isolated When you fire-up a browser in private/incognito/safe mode (sometimes more crudely- and accurately- referred to as "porn mode"), it will create a new, temporary database for LocalStorage values. That means anything saved to LocalStorage will be destroyed when the private browsing session is closed, making LocalStorage behave more like SessionStorage.
Additionally, since a browser's "Session Restore" feature does not re-open private mode sessions, anything created in SessionStorage will also be lost after the browser window is closed. Really, in short, any data put in Local or SessionStorage during a private browsing session will be lost as soon as the browser window is closed (intentionally or not).
Key sentence: any data put in Local or SessionStorage during a private browsing session will be lost as soon as the browser window is closed (intentionally or not).
Ironically enough, it's not a bug, it's a feature
.
As mentioned by Hyyan Abo Fakher
, you can find the same information on Web Storage API MDN
Solution 2:
This is indeed a bug reported on Firefox 59. It looks like it got fixed at some point, but was reported broken again on build 71. As of the time of writing of this answer it is still broken on FF 76.
Solution 3:
As mentioned above, it does not have a solution for this because it is the operating logic of the anonymous mode. However, a workaround would be to create a separate session class, ie create a global instance when starting the application so the client will not depend on the sessionStorage or internet connection. The idea would be to start the session global instance at the time of user authentication and after that use the same through the getter and setter to handle whatever is needed. The only bad side is the use of memory in abuse, you have to always clean up what you do not use and use maximum optimization that you can. I used this in some test applications with a good data load (thing of 50 thousand records being manipulated) and I had no problems with performance, sometimes it can help you :)
EX:
// IN TYPESCRIPT
interfaceCompanyInterface {
name: string,
enable : boolean
}
interfaceUserInterface {
name: string,
age: number,
company: CompanyInterface
}
interfaceSessionDataInterface {
token: string;
user: UserInterface;
}
classSession {
privatedata: SessionDataInterface;
publicgetData(key: string) {
returnthis.data[key];
}
publicsetData(key: string, value: any) {
returnthis.data[key] = value;
}
constructor(token: string | false = false) {
if (!token || token.length <= 10) {
// You Exception.....
}
}
}
// IN JAVASCRIPT
varSession = /** @class */ (function () {
functionSession(token) {
if (token === void0) { token = false; }
if (!token || token.length <= 10) {
// You Exception.....
}
}
Session.prototype.getData = function (key) {
returnthis.data[key];
};
Session.prototype.setData = function (key, value) {
returnthis.data[key] = value;
};
returnSession;
}());
Post a Comment for "Unable To Access Localstorage In Second Tab When Opened In Incognito [mozilla Firefox]"