Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restoring console.log()

For some reason, the prototype framework (or another JavaScript code) that is shipped with Magento is replacing standard console functions, so I can't debug anything. Writing down in JavaScript console console I get the following output:

> console Object assert: function () {} count: function () {} debug: function () {} dir: function () {} dirxml: function () {} error: function () {} group: function () {} groupEnd: function () {} info: function () {} log: function () {} profile: function () {} profileEnd: function () {} time: function () {} timeEnd: function () {} trace: function () {} warn: function () {} 

I'm using Google Chrome version 13.0.782.112 on Linux.

Prototype JavaScript framework, version 1.6.0.3

Is there a quick way to solve this?

like image 948
s3v3n Avatar asked Aug 17 '11 07:08

s3v3n


People also ask

What is the use of console log ()?

The console. log() is a function in JavaScript which is used to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user.

How do I enable console log?

Console Logs in Chrome: In Google Chrome, the Console Logs are available as a part of Chrome Dev Tools. To open the dedicated Console panel, either: Press Ctrl + Shift + J (Windows / Linux) or Cmd + Opt + J (Mac).

Does console log return anything?

The console. log() is a function that writes a message to log on the debugging console, such as Webkit or Firebug. In a browser you will not see anything on the screen. It logs a message to a debugging console.

Is console log bad for production?

Generally yes, its not a great idea to expose log messages in your production code. Ideally, you should remove such log messages with a build script before deployment; but many (most) people do not use a build process (including me).


2 Answers

Since original console is in window.console object, try restoring window.console from iframe:

var i = document.createElement('iframe'); i.style.display = 'none'; document.body.appendChild(i); window.console = i.contentWindow.console; // with Chrome 60+ don't remove the child node // i.parentNode.removeChild(i); 

Works for me on Chrome 14.

like image 115
Xaerxess Avatar answered Sep 27 '22 21:09

Xaerxess


For example,

delete console.log 

would also restore console.log:

console.log = null; console.log;         // null  delete console.log; console.log;         // function log() { [native code] } 
like image 25
pimvdb Avatar answered Sep 27 '22 22:09

pimvdb