Hello, I'm trying to put together a site without any JS frameworks outside Astro and I'm trying to propagate a new event on the window object for other frontend scripts to listen to when localStorage gets updated. The code is pretty simple:
const nativeSetItem = localStorage.setItem;
localStorage.setItem = function(key, value) {
const event = new Event('localStorageUpdated');
event.key = key;
event.value = value;
window.dispatchEvent(event);
nativeSetItem.apply(this, arguments);
};
I tried to add this inside a <script is:inline /> block, but I believe it is still only appended to the bottom of the rendered HTML. Is it then correct to assume that the bundled scripts are being run beforehand and therefore do not have access to this custom event I'm trying to propagate? Are there any alternative strategies for achieving this outside of ultimately having to encapsulate everything inside 1 astro component/using a UI framework?
Thanks in advance!