改变firebugx.js以适应IE开发人员工具

Bre*_*ett 7 javascript firebug internet-explorer

所述firebugx.js文件(如下所示)检查既!window.console和!console.firebug,如果安装萤火其正确检测.但是,该检查不适用于IE开发人员工具中的本机控制台对象 - 它会覆盖IE控制台对象.

例如,如果我包含firebugx.js代码,那么以下异常将不会出现在IE控制台中(它只会被吞下):

  function foo() {
    try {
      throw "exception!!!";
    }
    catch (e) {
      console.error(e);
    }
  }
Run Code Online (Sandbox Code Playgroud)

问题:适应IE开发人员调试器的最佳方法是什么?也许明显的答案是在IE中调试时简单地注释掉firebugx.js检查.还有其他方法吗?

参考:

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() {}
}
Run Code Online (Sandbox Code Playgroud)

Bre*_*ett 5

我想对firebugx.js进行以下修改可以解决问题.我只重新定义window.console(如果它不存在),然后可选地在window.console上定义缺少的函数.我对改变firebugx.js犹豫不决,但我不能真正看到它的缺点.这是在Firefox和IE调试器之间快速切换的最简单方法.

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 () { }
    }
  } 
}
Run Code Online (Sandbox Code Playgroud)