Why does my Chrome extension's Action Icon shown on all pages in omnibox?

邮差的信 提交于 2019-12-22 17:39:42

问题


I have following manifest

  "page_action": {
    "default_icon": {
      "19": "images/icon19.png",
      "38": "images/icon38.png"
    },
    "default_title": "Helper for soiduplaan.tallinn.ee"
  },
  "content_scripts": [
    {
      "matches": [
        "http://soiduplaan.tallinn.ee/*"
      ],

But I see icon of my app in all pages I visit:

What do I do wrong? =\


回答1:


Your current code is:

chrome.tabs.onUpdated.addListener(function(a) {
    chrome.pageAction.show(a);
});

This causes the page action to be shown whenever a page is loaded, ie for every tab.
If you want to restrict the page action to certain pages only, check the tab.url property:

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
    if (tab.url && tab.url.indexOf('http://soiduplaan.tallinn.ee/') === 0) {
        chrome.pageAction.show(tabId);
    }
});

For more info, read the docs for chrome.tabs.onUpdated.



来源:https://stackoverflow.com/questions/16855910/why-does-my-chrome-extensions-action-icon-shown-on-all-pages-in-omnibox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!