为什么我得到 Cannot call method 'addListener'未定义的?
我正在尝试制作 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"
]
}
,这是我的background.html
<body>
<script>
chrome.tabs.OnCreated.addListener(function(tab){
alert("fooooooo");
});
</script>
</body>
,在chrome调试器中我得到Uncaught TypeError:无法调用未定义的方法“addListener”。
我认为我正确设置了权限,但现在我真的不知道如何解决这个问题。有人可以帮忙吗?
im trying to make a chrome extension and i cant get my code to run.
this is the manifest
{
"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"
]
}
and this is my background.html
<body>
<script>
chrome.tabs.OnCreated.addListener(function(tab){
alert("fooooooo");
});
</script>
</body>
and in the chrome debugger i get Uncaught TypeError: Cannot call method 'addListener' of undefined.
ive set the permissions correctly i think, but now i really dont know how to fix this. can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它应该是
onCreated
,而不是OnCreated
。 JavaScript 区分大小写。Instead of
OnCreated
it should beonCreated
. JavaScript is case sensitive.