[英]chrome extension tab event listeners are not working
我希望我的扩展名能够捕获所创建的所有网址,并警告它对于chrome扩展名来说是全新的,这是我的第一个扩展名^ _ ^,这是manifest.json文件:
{
"name":"modz",
"manifest_version":2,
"version":"1.0",
"description":"this ext. will help you record all the urls you have visited",
"browser_action":
{
"default_icon":"icon.png",
"default_popup":"popup.html"
},
"permissions":[
"tabs"
]
}
这是html,其中包含scrpit:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
chrome.tabs.onCreated.addListener(function ( tab ){
alert(tab.url);
});
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
alert(changeInfo.url);
});
chrome.tabs.onActivated.addListener(function(activeInfo) {
chrome.tabs.get(activeInfo.tabId, function(tab){
console.log(tab.url);
});
});
</script>
<style type="text/css">
body{
width:440px;
}
</style>
</head>
<body>
<div id="hello">hi this is the pop up </div>
</body>
</html>
提前致谢
尝试将脚本代码放到background.js中,然后将其添加到清单中:
"background": {
"scripts": ["background.js"]
}
popup.html仅在用户单击浏览器操作图标时运行。 background.js将在整个会话中运行。
如果尚未查看此扩展指南,请访问: https : //developer.chrome.com/extensions/overview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.