Gra*_*ham 5 javascript firefox firefox-addon firefox-developer-tools firefox-addon-webextensions
有谁知道如何console.log()
在后台脚本中查看调用的输出?我可以在内容脚本中看到相同的输出.这是一个简单的脚本,我正在测试它:
这是我的background.js:
console.log("Message from background.js");
Run Code Online (Sandbox Code Playgroud)
这是我的manifest.json:
{
"name": "TestBed",
"manifest_version": 2,
"version": "1.0",
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_title": "Click"
},
"applications": {
"gecko": {
"id": "testbed@example.com",
"strict_min_version": "48.0a1"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我也在后台脚本中试过这个:
chrome.browserAction.onClicked.addListener(function() {
console.log('Message from background.js onclicked handler');
});
Run Code Online (Sandbox Code Playgroud)
我甚至像其他一些帖子所建议的那样卸载了Firebug,但这也没有任何区别(注意console.log
内容脚本有效).
有关在控制台中查看扩展程序输出的更一般答案,请参阅我的答案:Google Chrome/Firefox在控制台中看不到扩展程序输出.
您可以console.log()
在浏览器控制台中查看后台脚本 的输出.您可以使用OSX上的键盘快捷键Ctrl- Shift- J或Cmd- Shift- J或Firefox菜单栏:Tools➞WebDeveloper➞ 浏览器控制台打开浏览器控制台.
当版本测试WebExtensions大于或等于49,1我经常被滥用的不良特性,使扩展到打开浏览器控制台.alert()
后台脚本不支持该功能,但会打开浏览器控制台并在控制台中输出警报文本.2这样做适用于大于或等于49.0的Firefox版本.但是,它在早期版本的Firefox中引发了错误.
为了测试,我经常在我的后台脚本中包含以下内容:
//* For testing, open the Browser Console
try {
//alert() is not actually supported in Firefox WebExtension background scripts.
//This forces the Browser Console open.
//This abuse of a misfeature works in FF49.0b+, not in FF48.
alert('Open the Browser Console.');
} catch(e) {
//alert() throws an error in Firefox versions below 49.
console.log('alert() threw an error. Probably Firefox version < 49.');
}
//*
Run Code Online (Sandbox Code Playgroud)
alert()
,它还将在单独的行中输出:"后台窗口不支持"alert();请改用console.log."