Detect a console.warn message

The warnings you are talking about are generated by the browser, not console.warn. This is why you cannot override it. Most likely, you need to manually add listeners for each event you need. For example, if you want to handle a script loading error use the onerror event:

<script src="https://www.example.com/js/somescript1.js" onerror="console.log('Cannot load script from ' + this.src)"></script>
<script src="https://www.example.com/js/somescript2.js" onerror="console.log('Cannot load script from ' + this.src)"></script>


How about overriding the console.log()?

let tmpConsoleLog = console.log;
console.log = function(msg){
    // Intercept code goes here using msg variable
    alert(msg);
    // then perform the normal logging
    tmpConsoleLog(msg);
}

console.log("Something");

Tags:

Javascript