'Chrome local storage is not storing dates correctly [duplicate]

When setting data in Chrome's local storage containing a date, all the data is correctly retrieved except the date that disappears, but I really don't know what I am doing wrong.

await browser.storage.local.remove("ghunt");
var payload = {"ghunt": {
                "cookies": "dummydata",
                "date": new Date(),
                "step": "login"
            }};
console.log("Raw payload => ", payload);
console.log("Putting the payload in local storage...")
await browser.storage.local.set(payload)
console.log("Retrieving data from local storage...")
var storage = await browser.storage.local.get("ghunt");
console.log("Retrieved data => ", storage);

The exact same code / commands works perfectly on Firefox.

PS : I am using WebExtension-Polyfill from Mozilla to provide cross-browser support

Firefox output screenshot
Chrome output screenshot



Solution 1:[1]

MDN on StorageArea.set() (emphasis mine):

It's generally not possible to store other types, such as Function, Date, RegExp, Set, Map, ArrayBuffer, and so on. Some of these unsupported types will restore as an empty object, and some cause set() to throw an error. The exact behavior here is browser-specific.

Store new Date().getTime(), which is an integer, not new Date().

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Amadan