Is there any way to turn off all console.log
statements in my JavaScript code, for testing purposes?
After doing some research and development for this problem, I came across this solution which will hide warnings/Errors/Logs as per your choice.
(function () {
var origOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function () {
console.warn = function () { };
window['console']['warn'] = function () { };
this.addEventListener('load', function () {
console.warn('Something bad happened.');
window['console']['warn'] = function () { };
});
};
})();
Add this code before JQuery plugin (e.g /../jquery.min.js) even as this is JavaScript code that does not require JQuery. Because some warnings are in JQuery itself.
Thanks!!