console.log在Firefox,Greasemonkey脚本中使用时不起作用 [英] console.log is not working when used in a Firefox, Greasemonkey script

查看:228
本文介绍了console.log在Firefox,Greasemonkey脚本中使用时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的userscript使用 console.log()打印一些信息。



当我在Firefox(Greasemonkey)中安装此脚本时,Firefox中的Web控制台不显示任何内容。



我搜索了一个解决方案,并且有人建议使用 unsafeWindow 但它也不显示任何输出。而且 unsafeWindow 不能用于chrome。我甚至安装了Firebug,但没用。我怎样才能解决这个问题?



例如,我在Firefox中尝试这个脚本:

  // UserScript == 
// @name console
// == UserScript ==
console.log(hello);


解决方案

您的意思是在通过Greasemonkey ,对吧?
不久前, Greasemonkey破解了console.log (新!错误报告)。现在,要查看来自Greasemonkey的 console.log()调用的结果,您需要查看 Firefox的错误控制台,而不是Firebug的。


您可以按 Ctrl Shift J 来查看FF的错误控制台。



不过,您可以在两个Chrome浏览器中使用 unsafeWindow.console.log()和Greasemonkey脚本。 Chrome现在对 unsafeWindow 的支持有限。



如果您使用 unsafeWindow ,您可以访问所有的 Firebug的日志记录功能。 (Firebug必须安装,它们仍然可能在Chrome用户脚本中不起作用;我还没有过一段时间的测试。)






在Firefox中,如果Firebug未安装,或者对于页面没有激活,那么 unsafeWindow.console.log()调用将显示到新的Web控制台( Ctrl Shift K )。

您需要使用 unsafeWindow 当在Greasemonkey脚本中时。


$ b 注意Firefox目前支持 console.log() / code>, console.info() console.warn() console.error()本地 - 不需要Firebug。


My userscript prints some information using console.log().

This works fine in Chrome, but when I install this userscript in Firefox (Greasemonkey), the web console in Firefox is not displaying anything.

I searched for a solution and some suggested to use unsafeWindow but it is also not showing any output. Moreover unsafeWindow cannot be used for chrome. I even installed Firebug but it was no use. How can I resolve this?

For example, I tried this userscript in Firefox:

// ==UserScript==
// @name        console
// ==UserScript==
console.log("hello");

解决方案

You mean it doesn't work when installed via Greasemonkey, right?
Not long ago, Greasemonkey broke console.log (New! Bug report). Now, to see the results of a plain console.log() call from a Greasemonkey, you need to look in Firefox's Error console, not Firebug's.

You can see FF's Error console by pressing: CtrlShiftJ.

However, you can use unsafeWindow.console.log() in both Chrome and Greasemonkey scripts. Chrome now has limited support for unsafeWindow.

If you use unsafeWindow, you have access to the full range of Firebug's logging functions from Greasemonkey. (Firebug must be installed and they still might not work in Chrome userscripts; I haven't tested that way in a while.)


In Firefox, if Firebug is not installed, or it is not active for the page, then unsafeWindow.console.log() calls will display to the New "Web Console" (CtrlShiftK).
You need to use the unsafeWindow when inside a Greasemonkey script.

Note that Firefox currently supports console.log(), console.info(), console.warn(), and console.error() natively -- no Firebug required.

这篇关于console.log在Firefox,Greasemonkey脚本中使用时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆