简体   繁体   English

网页上的Fire扩展名Google Chrome扩展名

[英]Fire extension on very page Google Chrome Extension

I'm building a Google Chrome extension and want to autoload my extension on every new page, so that I can get the current url and check in a Database some data for it. 我正在构建一个Google Chrome扩展程序,并希望在每个新页面上自动加载该扩展程序,以便获取当前网址并在数据库中检入一些数据。 I want to do it a bit like the adblockers and show how many ads where blocked with the badgetext. 我想像adblockers那样做,并显示有多少广告被badgetext屏蔽了。 Anyway I don't get it workig to autoload on every new page I open. 无论如何,在打开的每个新页面上,我都无法自动加载。 It loades once and then stays there. 它加载一次,然后停留在那里。 It only reloads when I click on the Icon to get the popup.html. 仅当我单击图标以获取popup.html时,它才会重新加载。

Here my Manifest: 这是我的清单:

{
  "manifest_version": 2,

  "name": "Some name",
  "description": "Some desc.",
  "version": "1.0",
  "permissions": [
    "tabs",
    "background"
  ],
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },
  "background": {
    "scripts": ["background.js"],
    "persistent": false
  }
}

My background.js looks like this 我的background.js看起来像这样

chrome.windows.onFocusChanged.addListener(function(){
    chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
        // do some stuff with the new url
    });
});

Someone have a hint? 有人提示吗?

I would use chrome.tabs API instead of chrome.windows API. 我会使用chrome.tabs API而不是chrome.windows API。 http://developer.chrome.com/extensions/tabs.html http://developer.chrome.com/extensions/tabs.html

onCreated event and onUpdated event should work. onCreated事件和onUpdated事件应该起作用。

chrome.tabs.onCreated.addListener(function callback) chrome.tabs.onCreated.addListener(函数回调)

chrome.tabs.onUpdated.addListener(function callback) chrome.tabs.onUpdated.addListener(函数回调)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM