问题
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