I'm trying to detect caller function and where it came from.
For example :
Let assume we have following line on HTML content.
<script src="/somefunc.js"></script>
And following function located in somefunc.js
exampleFunction = function(){
var f = document.getElementById("hello")
}
As you see exampleFunction is calling getElementById() function. In order to detect that calls, I've override getElemenyById() with following codes.
document._oldGetElementById = document.getElementById;
document.getElementById = function(elemIdOrName) {
var result = document._oldGetElementById(elemIdOrName);
if (! result) {
var elems = document.getElementsByName(elemIdOrName);
if (elems && elems.length > 0) {
result = elems[0];
}
}
console.log("someone called me! Caller function = "+arguments.callee.caller);
return result;
};
but I couldn't manage to get information which function caller and what is it location ?I mean I want to get information like following output.
Caller = exampleFunction
Caller location = site.com/somefunc.js
Any idea ?