LocalStorage in chrome Incognito Mode - javascript

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?

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.

Related

Restore a session with cookies from another browser with Javascript

Let's say I am logged in (with login/password) on a website/service https://example.com in a browser. If I open Developer tools, I can run document.cookie in the console and copy the string containing all the cookies associated with the current website.
Then I open a new incognito window, I go to https://example.com. Of course, I'm not logged in. I can remove the current cookies with the method described in Clearing all cookies with JavaScript in the Developer tools console, and then restore the cookies copied before:
document.cookie = "<the string that I copied before>"
Then after a page reload (F5), I expected to be logged-in again, but it did not work. The cookies set with document.cookie = "<the string that I copied before>" are not kept. (For example, in the case of Reddit, it did not work.)
What's wrong with this JS approach to set cookies in the "Developer tools" from a previous session from another browser? Shouldn't it work?
Normally, the session id is set to server only, you can not get session id in JS/console.
Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Restrict_access_to_cookies

cookies not getting cleared in IE11 (cookie was set by writing to document.cookie via Javascript)

so I set some cookies manually via Javascript by writing to document.cookie and they are getting written fine.
I checked using
console.log(document.cookie)
My issue is that even if I manually cleared my history via
Internet options => Browsing History => Delete (making sure "Cookies
and other website data" is ticked)
Making sure "Delete browsing
history on exit" is ticked and "Cookies and other website data" is
also ticked
document.cookie still shows the cookie values I manually created.
Things I've tried:
Close the tab. Manually clear my history. And then reopen my page on a new tab
Close IE11 completely. Reopen the app. And then open my page on a new tab
Any ideas what I could be doing wrong?
Thanks
ps. While I can expire my cookie via Javascript. I cannot expect end users to do same. :)
I've seen this happen if the website is "a favorite" in IE11. Can you try the following?
Go to Internet options => Browsing History => Delete (untick "Preserve Favorites website data"). Click delete, and close IE11.
If your website is not a favorite, let me know.
If you've already cleared your cookies the normal way, have you tried unchecking (if set) the Preserver Favorites Website Data option under Delete Browsing History? Tools > Safety > Delete Browsing History OR Ctrl + Shift + Delete.
If the above doesn't work, try pressing F12 and then Ctrl + R to clear browser cache, confirm you want to delete the browser cache. There is also an option to clear cookies for that specific domain under the Cache tab in Developer Tools Window.
I had the same problem with IE11 working under Windows 8.1: somehow the delete Browser Cookie didn't take effect. I could verify it using Burp: the cookies were still sent to the website.
I tried the various options:
Internet options => Browsing History => Delete (untick "Preserve Favorites website data"). Click delete, and close IE11.
Manually typing 'Document.cookie = ""' into the Developer Console
Resetting IE to default configuration
The only thing that actually worked for me was clearing the Browser Cookies through the Developer Console, as mentioned by lloan. For IE11, it looks a bit different so if you are looking for it, here it is:
Open the Developer Tools using F12
Go to Network
Click on "Clear cookies for domain"
For screenshot, see here

window.open why some user's IE open new window every time.

This issue is driving me crazy, I have an app which is referenced via .asp pages and in one of these pages there is a javascript function to open a popup
window.open("popup.aspx", "myPopup","width=300,height=100,status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no,alwaysLowered=yes,location=no,directories=no,titlebar=no");
Looking up various documentation it has been stated that if the same window name is used then this window will be re-used. This is correct on most user's IE but on an some end users PC it opens an additional popup window even though the same code is being used.
To verify this I created a test.aspx and simply duplicated the open function previously stated. On my PC I got one popup window, on the some users got two. It’s definitely Internet Explorer on this PC because I have installed Firefox and there is no issue and the same window is referenced.
IE(11) version is same all.
What problem??
Save an object reference of the opened window to a global variable and do a validation before calling window.open:
var windowObjRef = null; // global variable
if(windowObjRef== null || windowObjRef.closed)
{
windowObjRef = window.open("popup.aspx", "myPopup","width=300,height=100,status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no,alwaysLowered=yes,location=no,directories=no,titlebar=no");
}
else
{
windowObjRef.focus();
}

Cookies doesn't appears in Chrome Console Resources tab

I'am working an a Grails app and create different cookies.
Some appears in the chrome console Resources TAB and some are not showing.
I need to get the value of these Cookies using Angularjs and can access only the one that are showing on console Resources TAB.
The other cookies are visible in the Chrome Content settings button.
In the Cookies section, but not in the Chrome console Resources TAB.
All cookies are created the same way:
Cookie cookie = new Cookie("username", username)
cookie.maxAge = 1209600 //14 days
cookie.httpOnly = true
response.addCookie(cookie)
Thanks for your help.
Ok the problem was the path. To be visible in all the page the path must be "/"
cookie.setPath("/")

window.name is not persistent in Google Chrome

I'm seeing a strange behavior in Google Chrome, using the window.name property.
For example:
open a tab and go to http://google.com .
Open up console, and type window.name="hello".
Now in the same tab, go to http://chase.com.
In the console, type window.name.
I expect to see "hello" returned, but instead I see "".
Is this a known issue for Google Chrome? It works for me in FireFox.
Anyone have any insight to this behavior?
Thanks!
Update:
If, instead of typing in a new URL, I type window.location="http://chase.com", then the window.name persists!
window is a global object for each document, not for the browser window. In a page with iframes you will have one window for each iframe for example. Each time a document is loaded, a new global object is created and populated for the context. When the document is unloaded, the global object along with all its data is destroyed.
Chrome might start a new process depending on the site.
I would call what Chrome does perfectly acceptable.
You really shouldn't be dependent on any global variable to be persistent. I would consider using session or local storage.

Categories