有没有办法从 Firefox 的 cfx 使用 Firebug 的 console.log?

发布于 2025-01-05 01:13:40 字数 70 浏览 3 评论 0原文

使用附加 SDK 的 cfx run 命令,是否可以让它登录 Firebug 控制台,而不是从主附加代码或内容脚本登录命令行?

Using the Add-on SDK's cfx run command, is it possible to get it to log to Firebug's console instead of the command line one from the main add-on code or content scripts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

莫相离 2025-01-12 01:13:40

您可以使用未记录的属性unsafeWindow。顾名思义,这是一个坏主意。但是,由于您仅使用它来调试,所以一切都应该没问题。请在发布您的插件时删除这些声明。

unsafeWindow.console.log("Hello, firebug!");

如果您想让所有控制台调用转到 firebug,您可以将以下内容放入内容脚本中。

console = unsafeWindow.console;

如果您只想记录

console.log = unsafeWindow.console.log

注意: 当我在 contentScriptWhen: "start" page-mod 上运行它时,我注意到 Firebug 尚未加载到控制台对象中。因此,如果您使用 contentScriptWhen: "start",则在访问控制台之前可能需要稍微延迟。

You can use the undocumented property unsafeWindow. As its name implies, this is a BAD IDEA. But, as you are only using it for debugging everything should be fine. Please remove these statements when releasing your addon.

unsafeWindow.console.log("Hello, firebug!");

If you want to make all console calls go to firebug you can put the following in your content script.

console = unsafeWindow.console;

If you just want log

console.log = unsafeWindow.console.log

Note: When I was running this on a contentScriptWhen: "start" page-mod I noticed that Firebug hadn't loaded into the console object yet. So if you are using contentScriptWhen: "start" you may need a slight delay before accessing the console.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文