Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Altering firebugx.js to Accommodate IE Developer Tools

The firebugx.js file (shown below) checks both !window.console and !console.firebug, which correctly detects if firebug is installed. However, that check does not accommodate the native console object in the IE developer tools -- it overwrites the IE console object.

For example, if I include the firebugx.js code, then the following exception will not appear in the IE console (it will just get swallowed):

  function foo() {
    try {
      throw "exception!!!";
    }
    catch (e) {
      console.error(e);
    }
  }

Question: What is the best approach for accommodating the IE developer debugger? Maybe the obvious answer is to simply comment out the firebugx.js check when debugging in IE. Are there other approaches?

Reference:

firebugx.js

if (!window.console || !console.firebug)
{
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
    "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

    window.console = {};
    for (var i = 0; i < names.length; ++i)
        window.console[names[i]] = function() {}
}
like image 529
Brett Avatar asked Feb 04 '11 17:02

Brett


1 Answers

I suppose the following modification to firebugx.js would solve the problem. I only redefine window.console if it does not exist and then optionally define the missing functions on window.console. I was hesitant to alter firebugx.js, but I can't really see a downside to this. It's the easiest way to quickly switch between the Firefox and IE debuggers.

firebugxCustom.js

if (!window.console) {
  window.console = {};
}
if (!window.console.firebug) {
  var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
    "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

  for (var i = 0; i < names.length; ++i) {
    if (!window.console[names[i]]) {
      window.console[names[i]] = function () { }
    }
  } 
}
like image 151
Brett Avatar answered Sep 29 '22 15:09

Brett