I have encountered this several times, & there is no explanation for it. There was no JS errors on the site. The code is indeed being executed. Replacing them with alert()
works just fine.
So today that happened again, so I tried to check the console object in the console object & I found some irregularities as if something has overwritten the console object.
The following screenshot is of the site (site A) where I have this problem:
http://ompldr.org/vZ256Mw/Selection_004.jpg
You see how log, warn & info are empty functions? and the console object is different from how it is on a site (site B) where console works fine (screenshot follows)?
http://ompldr.org/vZ256Mg/Selection_003.jpg
Now the code running on both the sites is exactly same. Site B is my local install and Site A is staging and I don't have anything in the code which overwrites the console object, so what could be an explanation for this behavior?
As per nfroidure's suggestion, I added that code in my head section before anything else and I got this: uncaught error! (anonymous function) (anonymous function)
, second of which points to a code in another library file which has the following in it:
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() {}
}
This is responsible because I think the if check is faulty. "console" in window
will be true & "firebug" in window
will be false for me in Chrome resulting in replacing the console methods. It should be &&
over there, no?
Update: After changing the operator to &&
it started to work on Site A, but I don't understand why it only gets triggered on one and not on another.
Yes, it will reduce the speed, though only negligibly. But, don't use it as it's too easy for a person to read your logs.
console. log(A); Parameters: It accepts a parameter which can be an array, an object or any message. Return value: It returns the value of the parameter given.
No. It means that when you invoke `console. log` in a browser it "logs" a reference to an object instead of serialising it. This log is still synchronous, but when you expand it in the console its properties are dereferenced and may be different from when the original log was made.
Looks like Site A has firebug included since console has methods that look a lot like the ones here: http://getfirebug.com/wiki/index.php/Console_API
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With