使用JavaScript从扩展中以编程方式打开Firefox浏览器控制台?

使用JavaScript从扩展中以编程方式打开Firefox浏览器控制台?,javascript,firefox-addon,xul,Javascript,Firefox Addon,Xul,我已尝试将附加到JavaScriptConsole()到按钮,但这不起作用(未定义的引用错误) 如何编程XUL按钮以打开firefox浏览器控制台,以便查看扩展中的日志 下面的代码片段将起作用 if(HUDService.getBrowserConsole())//它已经打开了吗? HUDService.getBrowserConsole().chromeWindow.focus(); 其他的 HUDService.toggleBrowserConsole(); 以下代码片段将起作用 if(HU

我已尝试将
附加到JavaScriptConsole()
到按钮,但这不起作用(未定义的引用错误)


如何编程XUL按钮以打开firefox浏览器控制台,以便查看扩展中的日志

下面的代码片段将起作用

if(HUDService.getBrowserConsole())//它已经打开了吗?
HUDService.getBrowserConsole().chromeWindow.focus();
其他的
HUDService.toggleBrowserConsole();

以下代码片段将起作用

if(HUDService.getBrowserConsole())//它已经打开了吗?
HUDService.getBrowserConsole().chromeWindow.focus();
其他的
HUDService.toggleBrowserConsole();

如果您所在的范围内没有HUDService,则要访问该服务,请执行以下操作:

var devtools = Components.utils.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools;
var HUDService = devtools.require("devtools/webconsole/hudservice");

如果您在HUDService不可用的范围内,则要访问它,请执行以下操作:

var devtools = Components.utils.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools;
var HUDService = devtools.require("devtools/webconsole/hudservice");