3

I am doing a very simple:

console.log("Testing");

along with :

alert("testing");

The Alert works (so I know the javascript is working) but I'm unable to see the log. When I use Firefox I get the following error:

The Web Console logging API (console.log, console.info, console.warn, console.error) has been disabled by a script on this page.

What is going on? I have looked at the following topics, but none have helped:

Chrome: console.log, console.debug are not working

console.log quit working in Chrome

Console.log not working in Chrome [closed]

why does console.log not output in chrome? Console.log not working at all

I have also made sure that the funnel is working and that logging is turned on.

What else could the problem be?

Community
  • 1
  • 1
BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156
  • Open up the console and type `console.toString()` What is returned? My bet it is a function and not an object. AKA someone overwrote console. – epascarello Jan 10 '14 at 19:53
  • I think this explains it pretty well: *"The Web Console logging API (console.log, console.info, console.warn, console.error) has been disabled by a script on this page"* figure out what script is disabling it. – Kevin B Jan 10 '14 at 19:54
  • 1
    possible duplicate of [Firefox Web Console Disabled?](http://stackoverflow.com/questions/8212373/firefox-web-console-disabled) – Kevin B Jan 10 '14 at 19:56
  • @epascarello nothing was returned on Chrome & Firefox – BlackHatSamurai Jan 10 '14 at 19:57
  • @KevinB considering that I'm having this issue with CHROME, I would have to disagree that this is a duplicate. – BlackHatSamurai Jan 10 '14 at 19:58
  • Okay if you "alert it" what does is show. Have you restarted your machine? ;) – epascarello Jan 10 '14 at 20:00
  • Just because the question i linked to only pointed out firefox doesn't mean chrome wasn't also affected. doing window.console = {} in chrome also leads to problems. – Kevin B Jan 10 '14 at 20:00
  • @epascarello the alert works and displays as expected. – BlackHatSamurai Jan 10 '14 at 20:01
  • Did you do `alert(console.toString());` ? Do you have any filters applied in the log? My bet is someone added code to hide the console logs. – epascarello Jan 10 '14 at 20:02
  • Most likely you have code on your page that does this: `window.console = { log: $.noop }` – Kevin B Jan 10 '14 at 20:02
  • @epascarello an object is returned – BlackHatSamurai Jan 10 '14 at 20:06
  • @KevinB I've searched for the code you suggested (using grep) and have not found anything similar to what you suggested. – BlackHatSamurai Jan 10 '14 at 20:16
  • It is there somewhere, there is no other way for this error to occur. – Kevin B Jan 10 '14 at 20:16
  • Do you have filters applied in the log and did you restart the browser[s] to make sure it is not a memory issue – epascarello Jan 10 '14 at 20:17
  • No filters. Yes, I've restarted the browser. – BlackHatSamurai Jan 10 '14 at 20:17
  • @KevinB I have searched the ENTIRE SITE using `grep -r "window.console={log: $.noop}" /Applications/MAMP/htdocs/wordpress` and there were no results. – BlackHatSamurai Jan 10 '14 at 20:29
  • i doubt it was actually using that exact text, there are hundreds of thousands of different possible ways it could be written to achieve the same result. – Kevin B Jan 10 '14 at 20:29
  • @KevinB Then why am I getting a js console message in Chrome saying `event.returnvalue is deprecated. Please use the standard event.preventdefault() instead`. If what you're saying is true, there shouldn't be any output, right? – BlackHatSamurai Jan 10 '14 at 20:33
  • No, that's not a console.log. That's a warning generated by the chrome javascript engine, raised due to something jquery is doing (it's fixed in the next version of jquery) – Kevin B Jan 10 '14 at 20:34
  • @KevinB, if you are right, how do I fix this. I've tried finding something similar to what you suggested but not having any luck. I'm able to use the console on the admin side of my wordpress site, but not on the front end, which led me to believe that it was an issue with the theme, but I only found one file that even referenced `window.console` – BlackHatSamurai Jan 10 '14 at 20:38
  • It's not going to be easy to fix, you're going to have to find that one file that is overriding the console. Here's an example of why that could be difficult. http://jsfiddle.net/jc7Za/ You have no way of knowing exactly how the console was overridden, therefore a straight up string search will have to look for `console` specifically and will likely come up with many results, and the one you're looking for might not appear that obvious when you see it. – Kevin B Jan 10 '14 at 20:42
  • @KevinB `JQMigrate` seems to be working... – BlackHatSamurai Jan 10 '14 at 21:16
  • working as in, it's able to send commands to the console? It might be using one of the methods that aren't overridden, such as console.warn. – Kevin B Jan 10 '14 at 21:18
  • It's using `window.console.log`, yes, working as sending commands to the console. – BlackHatSamurai Jan 10 '14 at 21:20
  • Turns out the theme developer had added firebug lite to the theme without me knowing. Turning it off fixed the problem. thank you all for your hep. – BlackHatSamurai Jan 10 '14 at 22:10

5 Answers5

1

I just came across this problem after a Firefox update and managed to fix it. Here's the code that caused the problem:

/* IE fix that allows me to still log elsewhere */
if (typeof(console)=="undefined") {
    var console = {
        output: null,
        log: function (str) {
            // we can't emulate the console in IE, but we can cache what's output
            // so that IE users can get it via console.output
            if (!this.output) this.output = new Array();
            this.output.push(new String(str));
        }
    };
    window.console = console;
}

In the previous version of FireFox, "var console;" wouldn't get executed. Now it seems to have added some sort of branching/prediction mechanism. Seeing that I may define a variable called console with global scope, it disables window.console.

I fixed this issue by renaming var console; to var cons;

/* IE fix that allows me to still log elsewhere */
if (typeof(console)=="undefined") {
    var cons = {
        output: null,
        log: function (str) {
            // we can't emulate the console in IE, but we can cache what's output
            // so that IE users can get it via console.output
            if (!this.output) this.output = new Array();
            this.output.push(new String(str));
        }
    };
    window.console = cons;
}

I still need to test this to make sure it does what I expect in IE, though. I just need to find a copy of IE without a console (I think 9 or below).

I just wish that Firefox would tell you what line of what script disabled the console - that would be nice.

1

I had the same issue with a Magento e-commerce site (version 1.6.2.0).

I fixed it commenting the following lines in /js/varien/js.js:637

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 fix is only (obviously) for Magento sites.

campsjos
  • 1,275
  • 15
  • 22
1

Turns out the theme developer had added firebug lite to the theme without me knowing. Turning it off fixed the problem.

BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156
0

I think the page you are viewing when trying to log via console.log() has a script in it which overwrites the property window.console.log. Usually this property is preset with a function by the browser but you a script may override it.

vanthome
  • 4,816
  • 37
  • 44
0

First suggestion: Do you use any other dev tools that use console? On Firefox I had the same problem with Firebug running on background without me noticing it, after closing firebug the error went away. Here's a possiple duplicate thread: Firefox Web Console Disabled?

Second, if it is overridden by some script, then one by one disable scripts and see which draws the error.

Community
  • 1
  • 1