I have an application that uses localStorage events. One window writes to the storage an the other one reacts. This has been working fine for months, and still does on Chrome, FF and IE10, but since my users started using IE11 - it occasionally breaks.
After deep investigations I've discovered that IE11 fires the onstorage event only if the number of character in the new value is under a certain number (4282 by my measurements).
Furthermore, if there is already a value under the same key, IE will only fire the event if the size of both the old value and the new one together are under that limit.
One important note: in all cases the value does get written to the storage. The storage size is not exceeded in any stage.
This is a small code sample to demonstrate the issue:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function handle_storage(event)
{
alert("event fired!");
}
window.addEventListener("storage", handle_storage);
var keyName = "keyName";
function writeToStorage()
{
var num = parseInt(document.getElementById("bla").value);
var customValue = "";
for(var i = 0; i<num; i++)
customValue+="c";
localStorage.setItem(keyName, customValue);
}
</script>
</head>
<body >
<button onclick="writeToStorage()">Write</button>
<input type="text" id="bla"/>
</body>
</html>
At first try it out with a small number - write 100 in the input and click the button. You will see the alert saying that the event had been fired.
Then try with a large number - 5000. You will see no alert.
Then try combinations of numbers, and you will see that each times the sum of both old and new value are over the limit - no event will be fired.
Is this a bug in IE11?
Am I missing something?
Is there any workaround?