I'm trying to override the localStorage.setItem
method to add a disable local storage option for debugging purpose. But I keep having a Illegal Invocation error when using the method.
let originalFunction = window.Storage.prototype.setItem;
window.Storage.prototype.setItem = (keyName, keyValue) => {
console.log("Override worked ! ")
let currentState = localStorage.getItem("disableStorage");
if (currentState === null || keyName === "disableStorage") {
originalFunction(keyName, keyValue);
}
return;
}
localStorage.setItem("test", "blah");
I've done a jsfiddle for you to test it, as in the code snippet, local storage won't work.
I've tried with and without window, it won't work either case.
We can't see it correctly in the jsfiddle but the error is at the line : originalFunction(keyName, keyValue)
I've done the override corresponding to this question. But it doesn't seems to work.