17

I'm trying to log some data from my javascript code to check if its right, but it doesn't seem to be working. Even when I type into the console:

console.log("hello");

the console just returns undefined (which is correct) but it also doesn't log the "hello". If it matters, I'm using adblock and hoverzoom as my extensions. Also, I'm on a macbook pro. Any ideas on why this doesn't work?

Cristiano
  • 2,839
  • 8
  • 25
  • 35
  • 1
    have you tried killing the chrome process and restarting it? – mkoryak Apr 01 '13 at 15:05
  • 1
    @adeneo nice april fools – Esailija Apr 01 '13 at 15:06
  • What platform? Because I can say that `console.log()` *definitely* works on my installation (Chrome 25 on Windows XP and Windows 7, and also in Chromium 24 on Ubuntu 12.10). – David Thomas Apr 01 '13 at 15:06
  • @mkoryak that worked! do you know why this wouldve happened? – Cristiano Apr 01 '13 at 15:08
  • check this http://stackoverflow.com/questions/9564110/javascript-console-log-not-working-in-this-context/20861058#20861058 ( worked for me ) – Abhishek Goel Dec 31 '13 at 17:30
  • 4
    Try running `delete console.log` in the console. See this: http://stackoverflow.com/a/7089671/631764 and this: http://stackoverflow.com/a/21954826/631764 ~~~ I don't see why this is closed or too localized. If this isn't helping anyone, why does it have 10,733 views and 7 upvotes for the question, and 8 for the answer? – Buttle Butkus Oct 25 '14 at 08:24
  • http://stackoverflow.com/questions/32515181/dynamically-inserted-script-tag-is-not-executed-in-the-correct-order – Larry Mar 28 '17 at 18:56
  • 1
    @ButtleButkus 's hint helped me – Pangur Apr 07 '22 at 13:18

3 Answers3

28

Most likely, you have some JavaScript in your code that overwrites console.log for compatibility reasons (this will also affect the console of the application's tab). You can verify that by pressing F12 in this tab and checking that console.log still works fine.

phihag
  • 278,196
  • 72
  • 453
  • 469
9

make sure 'Info' is checked in custom levels drop down. enter image description here

Rm558
  • 4,621
  • 3
  • 38
  • 43
0

I've had similar issues with javascript 'alert()' and 'console.log()' apparently not working in Chrome, but working in Firefox..

I didn't find a complete solution online, so I hope this helps someone.

After a bit of a journey I discover that it is a caching issue. Chrome was not recognising updated script files. Clearing the cache ( 'Ctrl-Shft-Del' on Chrome ) got it working.

I'm on a Wordpress platform so I tried using the js file timestamp as the version parameter in 'wp_enqueue_script()' as an attempt to cache-bust.

eg.

    $ver = filemtime( plugin_dir_path( __FILE__ ) . 'my-file.js' );

this didn't work! .I think that the timestamp is too big and gets truncated? Whatever the timestamp was, the url of the js file '?ver=xxxxxxx' was identical.

A simpler version parameter, however, DOES change the url and Chrome reloads every time the version parameter is changed.

eg.

    $ver = '1.24';

Solution:

        $timestamp = filemtime( plugin_dir_path( __FILE__ ) . 'my-file.js' );
        $ver = date( 'His', $timestamp ); 

$ver Resolves to something like '104323' ie. 10:43 and 23 seconds I reckon that should be unique enough!

Jerry S
  • 3
  • 3