微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Chrome 扩展调试 devtools.js 没有 console.log

如何解决Chrome 扩展调试 devtools.js 没有 console.log

不确定这是否是一个错误,但是当我创建 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 举报,一经查实,本站将立刻删除。