4

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?

3

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.

  • Thanks Marius, I hadn't looked in the 1.7 code for this, thanks for the update. With that in mind I'm not going to worry about dev/production versions of this – benz001 Aug 9 '13 at 1:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.