Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console.log not working inside of setInterval for Tampermonkey

I've used setInterval() plenty of times in typical scripts, but not with userscripts. For some reason, console.log() isn't working, but only inside of the setInterval. The alert, however, is working. Any ideas..? Should I not be using console.log?

To clarify, the first console.log("Started!"); does in fact print started.

(function() {
    console.log("Started!");
    setInterval(function(){ findAndReplace();}, 3000);
})();

function findAndReplace() {
    alert("hi");
    console.log("Hey");
} 
like image 449
Christopher Wirt Avatar asked Mar 07 '15 16:03

Christopher Wirt


2 Answers

The answer supplied by OPer didn't work for me, it seems that's no longer an option. Grant GM_log to your script and use the GM_log function as a substitute for console.log.

Add this to the script header... // @grant GM_log

Use this in your code... GM_log('<my debug message>');

like image 60
Sam Hall Avatar answered Oct 19 '22 10:10

Sam Hall


Apparently, Twitter overrides console.log. The "solution" is to put console.log = console.__proto__.log at the top of my functions.

like image 1
Christopher Wirt Avatar answered Oct 19 '22 08:10

Christopher Wirt