0

enter image description here

  • Under the 'Application' tab of chrome I've found there are multiple localstorage (please see the yellow box) like - https://stackoverflow.com , https://www.google.com etc.
  • I'm now in stackoverflow (#1)
  • I'm trying to add a new local storage by the name https://mytestdomain.com so I can see it in the yellow box
  • I've tried the following javascript code to achieve this
var testObject = { 'one': 1, 'two': 2, 'three': 3 };  
localStorage.setItem('https://mytestdomain.com', JSON.stringify(testObject));
  • but it always gets added under the localstorage - https://stackoverflow.com (#2, #3). It's not being added as a new localStorage

Can anyone help me here?

Thanks in advance.

Razib
  • 10,965
  • 11
  • 53
  • 80
  • 2
    It doesn't work like this. What you is a list of websites / domains / frames that are there on the current Chrome tab you are in, and it is showing the local storage data for each one of it. – Deepak Kamat Mar 10 '22 at 08:46
  • 1
    Whatever localStorage is generated will be based on your current website. You can not able to generate the localStorage for another site. – Kaushikkumar Parmar Mar 10 '22 at 08:48
  • @DeepakKamat, thanks for your comment. I also think so. But when open `facebook.com` in other tab I can not see this `www.facebook.com` in current tab (stackoverflow). Furthermore while I go to the other tab (facebook tab) I do not see these local storeage from the yellow boxe. B – Razib Mar 10 '22 at 08:54

1 Answers1

1

That yellow box in the image represents all the sites which are storing some data in your localstorage. You cannot add a sitename (i.e https://mytestdomain.com) using localstorage.setItem().

Using localstorage.setItem('key', 'val') only set value in current domain's local Storage

If you want some value under https://mytestdomain.com domain, there should be a site with url - https://mytestdomain.com storing something in your localstorage.

Check here in the official doc for more info - Documentation Link

Ankit Saxena
  • 1,067
  • 1
  • 4
  • 16