Keyslinger
Keyslinger

Reputation: 5274

Stop Firebug from displaying console output from a single file

I have a page with a couple of scripts it's using:

<script src="thirdparty.com/js/foo.js"></script>
<script src="bar.js"></script>

I need to use console.log() to print some things in bar.js, but the output keeps getting buried in all of the stuff foo.js prints to the screen which I don't care about. I don't have access to foo.js to make changes to it and removing it is out of the question.

How can I make Firebug stop console printing from foo.js and continue to allow printing from bar.js?

Upvotes: 1

Views: 142

Answers (3)

KarelG
KarelG

Reputation: 5244

"don't have access to foo.js". If that file is a released file, then say to that developer that having debug statements on released files is a big no no.

Currently, you cannot filter messages from files in Firebug. See issue 2955. (For the Firefox built-in DevTools see bug 905978) But, you can use console.clear() statement at the first line of your JavaScript file to clear the console messages from the previously loaded script files.

However this does not guarantee to prevent other messages coming from other files if they have event handlers or functions with AJAX.

PS: Perhaps you have mixed foo.js with bar.js in your post. Your coding block says that bar.js is from third party while you're talking about foo.js being the culprit.

Upvotes: 1

Max
Max

Reputation: 1131

Before Including foo.js try to execute the following JS:

var _console = window.console;

window.console = {
  log: function() {},
  dir: function() {},
  .....
}

In this case you will have empty functions for foo.js.

In bar.js you can use _console.

If this is acceptable solution for you, you can think on its improvement.

Upvotes: 2

Marcos Gonz&#225;lez
Marcos Gonz&#225;lez

Reputation: 172

How about console.clear() function in bar.js before your console.log() calls?

Upvotes: 0

Related Questions