I am overriding console.warn to capture the warnings that are printed into the console of the web browser like this and the file in which I am doing this is track.js shown below. The code works absolutely fine.
File 1
// Filename - track.js
function getWarnStatements() {
window.warnStatements = [];
var oldWarn = console.warn;
console.warn = function (message) {
oldWarn.apply(console, arguments);
window.warnStatements.push({
type: 'console.warn',
data: message,
});
};
}
File 2
// Filename - xyz.js
console.warn('Hello World');
Let's say I have used console.warn() in some other file which is xyz.js and both track.js and xyz.js runs at the same time. When we normally check the browser console for the warning we will see the file name on the right side of the warning in the console and when we click on the filename it will take us to the javascript file in which the console.warn was written.
ISSUE
Check the image below. Instead of showing xyz.js it is showing track.js. How can i prevent this behavior. I want it to take the user to the correct file where console.warn was used instead of the file where I am over riding it because it will result in misleading the other developers to the wrong file.
