问题描述
不确定这是否是一个错误,但是当我创建 devtools 扩展时,“devtools_page”html 文件(即我添加 devtools 面板的位置)中引用的 JS 文件,它没有似乎曾经输出日志输出。我可以在 background.js 和 content.js 中看到它,但在 devtools.js 中看不到。请注意,这是在 Firefox 中登录的。我看到消息正在传递,因此侦听器正在触发至少。有什么想法吗?
// devtools.js
console.log('devtools');
const b = chrome || browser;
b.devtools.panels
.create("Example","/icons/star.png","/panel/panel.html",function (newPanel) {
newPanel.onShown.addListener(function() {
b.tabs.query({active: true,currentwindow: true},function (tabs) {
b.tabs.sendMessage(
tabs[0].id,{greeting: "hello"},function (response) {
console.log("I AM THE RESPONSE");
}
);
});
});
});
// content.js
console.log('content');
const b = chrome || browser;
b.runtime.onMessage.addListener(function (request,sender,sendResponse) {
console.log(
sender.tab
? "from a content script:" + sender.tab.url
: "from the extension"
);
if (request.greeting == "hello") sendResponse({farewell: "goodbye"});
});
// background.js
console.log('background');
{
"description": "__MSG_description__","manifest_version": 2,"default_locale": "en","name": "Example","version": "1.0","author": "author","homepage_url": "","icons": {
"48": "icons/star.png"
},"background": {
"scripts": ["background.js"]
},"content_scripts": [
{
"matches": ["<all_urls>"],"js": ["content.js"]}
],"permissions": [
"<all_urls>"
],"devtools_page": "index.html"
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)