Christopher Wirt Christopher Wirt - 1 month ago 16
Javascript Question

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");
}

Answer

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

Comments