【问题标题】:why am i getting Cannot call method 'addListener' of undefined?为什么我无法调用未定义的方法“addListener”?
【发布时间】:2011-05-19 13:19:02
【问题描述】:

我正在尝试制作 chrome 扩展,但我无法让我的代码运行。 这是清单

  {
  "name": "My First Extension",
   "version": "1.0",
   "description": "The first extension that I made.",
 "browser_action": {
 "default_icon": "icon.png"
 },
 "background_page": "background.html",
 "permissions": [
 "*://*",
"tabs"
]
}

这是我的背景.html

 <body>
<script>
chrome.tabs.OnCreated.addListener(function(tab){
    alert("fooooooo");

});
</script>
</body>

在 chrome 调试器中我得到 Uncaught TypeError: Cannot call method 'addListener' of undefined.

我认为我正确设置了权限,但现在我真的不知道如何解决这个问题。谁能帮忙?

【问题讨论】:

    标签: google-chrome google-chrome-extension


    【解决方案1】:

    应该是onCreated,而不是OnCreated。 JavaScript 区分大小写。

    【讨论】:

      猜你喜欢
      • 2017-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-06
      • 1970-01-01
      • 2017-04-20
      • 2019-08-14
      相关资源
      最近更新 更多