Magento – How best to restore the javascript console in Chrome/ developer tools in dev environment

debuggingjavascript

I've noticed that the javascript console object doesn't work on Magento sites when using any developer tools other than firebug. So debugging javascript with statements like console.log("something") doesn't work in Chrome for instance.

This seems to be done in /web/js/varien/js.js where a dummy console object is created and

if (!("console" in window) || !("firebug" in console))
{
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() {}
}

I'm guessing it's done to stop the various 3rd party scripts from sending log data to the console in production or to stop it from crashing in browsers that don't have a native console object.

I can comment out that code, but I'm guessing that's not what the team at Varien do when working on javascript (or perhaps they only use firebug…).

So what's the smart way to do this so that I've got it in my development environment but I don't accidentally push it to production?

Best Answer

This depends on the Magento version. For version CE 1.7 the piece of code you wrote is commented out. In 1.6 and lower it's not.
Knowing this, I assume it's safe to comment the code and not worry about future upgrades.

Related Topic