localStorage.on
Adds an event callback for changes in localStorage. Also see localStorage.set().
localStorage.on(eventName, callback);Input
Variable | Required | Description |
|---|---|---|
| yes | The name of the event. Currently, only the |
| yes | The callback function to trigger when the event occurs. It has the signature function(entry, value, script)where: |
Output
This function does not return anything.
Limitations
See localStorage.set() for storage limitations.
Comments
Use this function to detect when other scripts perform a localStorage.set() operation.
The "update" event does not trigger for localStorage.set() calls made within the same script.
Examples
To see how localStorage.on("update") works, you’ll need two scripts:
Listener Script:
localStorage.on("update", function(entry, value, script) {
console.log("localStorage got updated:", entry, "=", value, "by script", script);
exit();
});Initiator Script:
localStorage.set("data", "data from 1");
exit();How to Run:
Launch the Listener script (it will keep running).
Launch the Initiator script (it will run and stop).
Switch back to the Listener script and check its runtime logs — it should show the update event.