chrome.extensions.onRequest.addListener不会调试?

时间:2010-09-14 18:00:18

标签: javascript-events google-chrome

我到处寻找解决方案......甚至谷歌自己的代码示例都不起作用。有人请向我解释如何调试事件监听器或至少如何使Console.Log()工作!

查看Google的示例:http://code.google.com/chrome/extensions/messaging.html

这是我正在测试的...在我的background.js上(从我的background.html引用)我有这个:

chrome.extension.onRequest.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"});
    else
      sendResponse({}); // snub them.
  });

在我的popup.js上(从我的popup.html引用)我有这个:

chrome.extension.sendRequest({greeting: "hello"}, function(response) {
  console.log(response.farewell);
});

考虑到我的清单中有以下权限:

"permissions": ["http://*/", "tabs"],

我的内容脚本定义如下:

 "content_scripts": 
 [
  {
   "matches":   ["http://*/*", "https://*/*"],
   "js":    ["scripts/background.js"],   
   "all_frames":  true
  }
 ]

为什么我无法从console.log获取任何信息或调试到事件中?我得到的反应很好......但是我无法调试?

感谢您的帮助!

1 个答案:

答案 0 :(得分:7)

这是一个ooooollld问题,但是对于有同样问题的人:转到chrome:// extensions /(或工具 - >扩展程序),启用调试视图,然后应该在解压缩后加载链接用于检查background.html视图的扩展程序,该视图是输出来自background.html的控制台消息的地方。

相关问题