简体   繁体   English

Console.log 在 Tampermonkey 的 setInterval 内不起作用

[英]Console.log not working inside of setInterval for Tampermonkey

I've used setInterval() plenty of times in typical scripts, but not with userscripts.我在典型的脚本中使用了很多次setInterval() ,但没有使用用户脚本。 For some reason, console.log() isn't working, but only inside of the setInterval.出于某种原因, console.log()不起作用,但仅在 setInterval 内。 The alert, however, is working.然而,警报正在发挥作用。 Any ideas..?有任何想法吗..? Should I not be using console.log?我不应该使用 console.log 吗?

To clarify, the first console.log("Started!");为了澄清,第一个console.log("Started!"); does in fact print started.实际上打印开始了。

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

function findAndReplace() {
    alert("hi");
    console.log("Hey");
} 

The answer supplied by OPer didn't work for me, it seems that's no longer an option. OPer 提供的答案对我不起作用,似乎不再是一个选择。 Grant GM_log to your script and use the GM_log function as a substitute for console.log.将 GM_log 授予您的脚本并使用 GM_log 函数代替 console.log。

Add this to the script header... // @grant GM_log将此添加到脚本头... // @grant GM_log

Use this in your code... GM_log('<my debug message>');在您的代码中使用它... GM_log('<my debug message>');

Apparently, Twitter overrides console.log.显然,Twitter 覆盖了 console.log。 The "solution" is to put console.log = console.__proto__.log at the top of my functions. “解决方案”是将console.log = console.__proto__.log放在我的函数顶部。

To your tamermonkey script header add在您的 tamermonkey 脚本头中添加

// @grant GM_log

then console.log("hello world");然后console.log("hello world"); should work应该管用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM