4

I have no choice but to use some ancient js lib provided by a client. So no way I can fix the errors, and no way I can find a better solution. The source is unalterable.

Given that scenario, is there any way I can suppress the warnings or errors from that external library? Even if it is something like they had a console log somewhere in there. I'd like to prevent this script from flooding my console with unnecessary information.

Anyone dealt with that before?

Kai Qing
  • 18,793
  • 5
  • 39
  • 57
  • Have you checked this question? https://stackoverflow.com/questions/39634926/how-to-disable-console-log-messages-based-on-criteria-from-specific-javascript-s – jmargolisvt Aug 03 '17 at 17:07
  • @jmargolistv - Just read it over, it looks like selective console suppression and not really a mute for an entire script. My biggest pain is the exceptions and invalid state errors. It's a 2 page wall of useless on every click. – Kai Qing Aug 03 '17 at 17:18

1 Answers1

0

NOTE:

  • This is dirty!
  • This is not recommended!

... but this is how you can do it

var newConsole = jQuery.extend(true, {}, console);
console.log = console.info = console.error = function noop(){}; //etc

// some old crusty lib that you cannot modify

console.log("hey!");
newConsole.log("hey!");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
jeanfrg
  • 2,366
  • 2
  • 29
  • 40
  • Not bad and dirty is OK if it's just to get rid of nuisance pollution, but this is only good for silencing console. I'm really being plagued by DOMExceptions, InvalidStateError, etc. I want all noise from the external sources to go away. Thanks though – Kai Qing Aug 03 '17 at 17:15
  • @KaiQing unfortunately I don't know of a way to silence those. – jeanfrg Aug 03 '17 at 17:22
  • No problem. I've been doing this for over 10 years and I never thought to try until now. Live and learn – Kai Qing Aug 03 '17 at 17:49