Files
ladybird/Tests/LibWeb/Text/input/HTML/session-storage-event-fired-to-lazy-window.html
Shannon Booth cc711a6060 LibWeb/HTML: Fire storage events to windows without a Storage
Storage objects are created lazily when window.localStorage or
window.sessionStorage is first accessed. Previously, broadcast()
iterated over already-created Storage objects, so windows that had never
accessed these properties would not receive storage events.

Fix this by iterating over all active windows and initializing Storage
objects as part of the broadcast loop so all eligible windows receive
the event regardless of whether they had previously accessed
their storage property.
2026-03-16 13:55:07 +01:00

31 lines
1.1 KiB
HTML

<!DOCTYPE html>
<script src="../include.js"></script>
<script>
// Verify that a storage event is fired to a window that has not yet accessed
// sessionStorage - i.e. its Storage object has not yet been lazily created.
// See: https://github.com/whatwg/html/issues/10135
asyncTest(async (done) => {
const key = 'my-key';
const eventReceived = Promise.withResolvers();
window.onStorageEventReceived = eventReceived.resolve;
const iframe = document.createElement('iframe');
iframe.src = '../../data/session-storage-event-iframe.html';
const iframeLoaded = new Promise(resolve => { iframe.onload = resolve; });
document.body.appendChild(iframe);
await iframeLoaded;
sessionStorage.setItem(key, 'hello');
const e = await eventReceived.promise;
println(`key: ${key}`);
println(`oldValue: ${e.oldValue}`);
println(`newValue: ${e.newValue}`);
println(`storageArea: ${e.storageAreaString}`);
sessionStorage.removeItem(key);
done();
});
</script>