Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

console.log doesn't work sometimes

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.

like image 402
Ashfame Avatar asked Dec 12 '12 16:12

Ashfame


People also ask

Does Console log slow down server?

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.

Does Console log return anything?

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.

Is Console log synchronous or asynchronous?

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.


1 Answers

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

like image 53
Treborbob Avatar answered Sep 18 '22 17:09

Treborbob