为什么我的Chrome扩展程序的操作图标显示在多功能框中的所有页面上? [英] Why does my Chrome extension's Action Icon shown on all pages in omnibox?

查看:266
本文介绍了为什么我的Chrome扩展程序的操作图标显示在多功能框中的所有页面上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下清单:

 page_action:{
default_icon:{
19:images / icon19.png,
38:images / icon38.png
},
default_title:助手for soiduplaan.tallinn.ee
},
content_scripts:[
{
匹配:[
http://soiduplaan.tallinn.ee/*
] ,

但是我在所访问的所有页面中看到我的应用的图标:


我做错了什么? = \

解决方案

您当前的代码是:

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

这会导致页面动作在页面加载时显示,即每个页面。 >
如果您只想将页面操作限制到特定页面,请检查 tab.url 属性:

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

有关更多信息,请阅读
>

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? =\

解决方案

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.

这篇关于为什么我的Chrome扩展程序的操作图标显示在多功能框中的所有页面上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆