window.localStorage.setItem does not do anything

Talk about code development, features, specific bugs, enhancements, patches, and similar things.
Forum rules
Please keep everything here strictly on-topic.
This board is meant for Pale Moon source code development related subjects only like code snippets, patches, specific bugs, git, the repositories, etc.

This is not for tech support! Please do not post tech support questions in the "Development" board!
Please make sure not to use this board for support questions. Please post issues with specific websites, extensions, etc. in the relevant boards for those topics.

Please keep things on-topic as this forum will be used for reference for Pale Moon development. Expect topics that aren't relevant as such to be moved or deleted.
humbird0

window.localStorage.setItem does not do anything

Unread post by humbird0 » 2020-08-29, 06:01

Software
Windows 7 (64-bit)
Pale Moon desktop version 28.12.0 (64-bit)


PC Hardware
CPU: AMD A8-5600k
RAM: 16GB
GPU: AMD Radeon R9 200


Description
When running in Pale Moon, JavaScript detects the existence of this function:

Code: Select all

window.localStorage.setItem( "myVar", "myValue" );
But calling that function doesn't have any effect.

But local storage has an alternative syntax which does work in Pale Moon, and most other browsers.

Code: Select all

window.localStorage.myVar = "myValue";
Both syntax's are valid according to the standard, but setItem() and getItem() are commonly preferred because they carry no risk of clobbering the default properties of the localStorage API.


Unknown Bug?
The Bugzilla forum seems to have hundreds of reports about various localStorage issues over the past decade, but I didn't notice any discussing setItem() specifically. It's hard to be certain. That said, I did not encounter this behavior in the 3-year-old version of Firefox that I also tested it with.


Repeatable Steps
Try to set a string value using

Code: Select all

window.localStorage.setItem( "myVar", "myValue" );
The storage tab in the web inspector shows no change.
Try to set a string value using

Code: Select all

window.localStorage.myVar = "myValue";
The storage tab in the web inspector DOES show a change.


Expected Result
Both of these should produce the same result: Storing a string in Local Storage.

Code: Select all

window.localStorage.setItem( "myVar", "myValue" );

Code: Select all

window.localStorage.myVar = "myValue";

Actual Result
Does not create nor modify any value.

Code: Select all

window.localStorage.setItem( "myVar", "myValue" );
Stores a value:

Code: Select all

window.localStorage.myVar = "myValue";

User avatar
moonbat
Knows the dark side
Knows the dark side
Posts: 4981
Joined: 2015-12-09, 15:45

Re: window.localStorage.setItem does not do anything

Unread post by moonbat » 2020-08-29, 08:38

Confirmed in scratchpad.
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35636
Joined: 2011-08-28, 17:27
Location: Motala, SE

Re: window.localStorage.setItem does not do anything

Unread post by Moonchild » 2020-08-29, 08:44

I just used scratchpad in the browser context of this forum with the form:

Code: Select all

window.localStorage.setItem( "myVar", "myValue" );
And when inspecting the result in devtools, localstorage has the data stored.

i.e.: unable to reproduce.
You do not have the required permissions to view the files attached to this post.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

User avatar
RealityRipple
Astronaut
Astronaut
Posts: 663
Joined: 2018-05-17, 02:34
Location: Los Berros Canyon, California

Re: window.localStorage.setItem does not do anything

Unread post by RealityRipple » 2020-08-29, 15:30

Did you guys forget to refresh the local storage database after adding an item?

humbird0

Re: window.localStorage.setItem does not do anything

Unread post by humbird0 » 2020-08-29, 16:41

RealityRipple wrote:
2020-08-29, 15:30
Did you guys forget to refresh the local storage database after adding an item?
I don't see any commands in the local storage API for "refreshing the database"
All the online examples and browsers I've tested it on store the data instantly, without needing to reload the webpage.
https://developer.mozilla.org/en-US/doc ... torage_API
Pale Moon also instantly stores the data when you use this syntax:
window.localStorage.myVar = "myValue";
In the very least, there's an inconsistency in the way Pale Moon is behaving between the two syntax's.

I found this bug while debugging an issue with my own website which has an option to save a persistent search. I worked around the problem using the "variable assignment" syntax above.

humbird0

Re: window.localStorage.setItem does not do anything

Unread post by humbird0 » 2020-08-29, 16:49

I wonder if it had anything to do with testing it in a simulated server?
I was using NodeJS and accessing the test-site using localhost.
Perhaps the behavior is different online?
Other browsers didn't have any problem with it.

But that still wouldn't explain why one syntax was working and not the other one.

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35636
Joined: 2011-08-28, 17:27
Location: Motala, SE

Re: window.localStorage.setItem does not do anything

Unread post by Moonchild » 2020-08-29, 18:48

To be sure I called up the following official web demo by Mozilla: https://mdn.github.io/dom-examples/web-storage/
That uses the API functions (and not the property assignment method) as well, and it works 100%.

Additionally, I think if something as fundamental to a lot of websites as local storage was broken in Pale Moon, we'd be seeing a hell of a lot more bug reports about it :P

Do keep in mind that local storage is host-specific (not just domain), so if your URL's host is somehow different when you try to recall stored data, it won't work.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

humbird0

Re: window.localStorage.setItem does not do anything

Unread post by humbird0 » 2020-08-29, 23:23

Hmm... that demo seems to work perfectly, even when I download everything and run it offline from my hard drive.
I guess the weird localStorage quirk I saw must have been caused by something else interfering with it somehow? That's definitely possible. My website is fairly complex.

If that's the case, then it probably isn't much to worry about since I was able to work around it.

New Tobin Paradigm

Re: window.localStorage.setItem does not do anything

Unread post by New Tobin Paradigm » 2020-08-29, 23:55

Well always a good idea to double check in practical tests.

User avatar
RealityRipple
Astronaut
Astronaut
Posts: 663
Joined: 2018-05-17, 02:34
Location: Los Berros Canyon, California

Re: window.localStorage.setItem does not do anything

Unread post by RealityRipple » 2020-08-30, 00:47

humbird0 wrote:
2020-08-29, 16:41
RealityRipple wrote:
2020-08-29, 15:30
Did you guys forget to refresh the local storage database after adding an item?
I don't see any commands in the local storage API for "refreshing the database"
All the online examples and browsers I've tested it on store the data instantly, without needing to reload the webpage.
https://developer.mozilla.org/en-US/doc ... torage_API
Pale Moon also instantly stores the data when you use this syntax:
window.localStorage.myVar = "myValue";
In the very least, there's an inconsistency in the way Pale Moon is behaving between the two syntax's.

I found this bug while debugging an issue with my own website which has an option to save a persistent search. I worked around the problem using the "variable assignment" syntax above.
I meant pressing the little "reload" button above the key/value list in the developer tools when Local Storage is selected.