chrome tabs事件不适用于背景js

时间:2014-12-06 06:28:33

标签: google-chrome-extension tabs

在我的许可下

 "background": {
      "scripts": [ "request.js" ]
   },
   "browser_action": {
      "default_icon": "uefa.png",
      "default_popup": "popup.html",
      "default_title": "as2"
   },
   "content_scripts": [ {
      "js": [ "content.js" ],
      "matches": [ "http://*/*", "https://*/*" ]
   } ],
   "description": "moving",
   "manifest_version": 2,
   "name": "as2",
   "permissions": [ "http://*/*", "https://*/*", "tabs", "webRequest", "webRequestBlocking", "storage", "webNavigation", "\u003Call_urls>", "cookies" ],
   "update_url": "https://clients2.google.com/service/update2/crx",
   "version": "1.4",

and request.js

chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab)
{   
alert("onUpdated"+tab.url);
});

chrome.tabs.onActivated.addListener(function(activeInfo) {
 alert("onActivate"+tab.url);
}); 

chrome.windows.getAll({populate:true},function(windows)
{
 windows.forEach(function(window)
 {
  window.tabs.forEach(function(tab)
  { 
    if(tab.url.indexOf("https://www.bet-at-home.com/en/sport/live/") != -1)
    {
      alert("ssdsf::"+tab.id);
    }               
    });
  });
}); 

效果很好! 但问题是如果没有调试窗口,它永远不会工作。 有谁知道这些错误?

它已经具有制表符权限,并且也没有工作tabs.remove。

1 个答案:

答案 0 :(得分:0)

你能更具体一点吗?我使用空白popup.html运行您的代码,并且以下manifest.json和onUpdated工作正常:

{
   "background": {
      "scripts": [ "request.js" ]
   },
   "browser_action": {
      "default_popup": "popup.html",
      "default_title": "as2"
   },
   "description": "moving",
   "manifest_version": 2,
   "name": "as2",
   "permissions": [ "tabs" ],
   "version": "1.4"
}