I've managed to instrument functions in Javascript by creating another function, adding my own functionality to it and then invoking apply(this, arguments)
:
window["functionA"] = function(){...}
On Google Chrome I also managed to instrument function setItem
which belongs to localStorage
so instead I wrote:
localStorage["setItem"] = function(){...}
The above works brilliantly, writing localStorage.setItem
instead of localStorage["setItem"]
also works.
Although this works on Google Chrome, on Firefox localStorage["setItem"]
or localStorage.setItem
are treated as stored items in localStorage
instead of new functions, so whenever localStorage["setItem"] = function(){...}
is invoked, function() {...}
is stored as a String in location setItem
in localStorage
. Does anybody have any idea why Firefox treats this differently than Chrome or if there exists any sort of work around to this problem?
Have you tried patching the prototype of Storage instead?
Storage.prototype.setItem = function(key, value)
{
//
}