Javascript chrome扩展选项卡事件侦听器不工作
我想让我的扩展捕获任何创建的url,并提醒它对chrome扩展是全新的,这是我的第一个扩展^_^ 以下是manifest.json文件:Javascript chrome扩展选项卡事件侦听器不工作,javascript,google-chrome,Javascript,Google Chrome,我想让我的扩展捕获任何创建的url,并提醒它对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": {
{
"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>
chrome.tabs.onCreated.addListener(函数(选项卡){
警报(tab.url);
});
chrome.tabs.onUpdate.addListener(函数(tabId、changeInfo、tab){
警报(changeInfo.url);
});
chrome.tabs.onActivated.addListener(函数(activeInfo){
chrome.tabs.get(activeInfo.tabId,函数(tab){
console.log(tab.url);
});
});
身体{
宽度:440px;
}
嗨,这是弹出窗口
提前感谢尝试将脚本代码放在background.js中,并将其添加到清单中:
"background": {
"scripts": ["background.js"]
}
popup.html仅在用户单击浏览器操作图标时运行。background.js将在整个会话中运行。如果还没有,请查看此扩展指南:然后我应该在html文件中包含js文件还是在清单中声明它?只要在清单中声明它,扩展就会自动运行它。您根本不需要popup.html或浏览器操作。