[英]how to dynamically change chrome extension icon
I am developing a chrome extension. 我正在开发chrome扩展程序。 The scenario is kind of
该场景是
When i click on the icon extension send POST request to server and on basis of the GET response it procceds on any of 3 different if/else if/ else statement. 当我单击图标扩展名时,将POST请求发送到服务器,并根据GET响应在3种不同的if / else if / else语句中的任何一种上进行处理。 I am using page action to show the icon next to address bar.
我正在使用页面操作在地址栏旁边显示图标。 I want my extension icon to change dynamically on each if/else if /else statement.
我希望扩展图标在每个if / else if / else语句上动态更改。
this is my backgound.js to make the icon visible next to address bar. 这是我的backgound.js,使该图标在地址栏旁边可见。
chrome.runtime.onInstalled.addListener(function() {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([
{
conditions: [
new chrome.declarativeContent.PageStateMatcher({
})
],
actions: [ new chrome.declarativeContent.ShowPageAction() ]
}
]);
}); }); });
});
this is my manifest.json 这是我的manifest.json
"page_action" :
{
"default_icon" : "icon-191.png",
"default_title" : "xxx",
"default_popup": "popup.html"
}, },
Any suggestion how can i change extension toolber icon dynamically on diffetent statement? 有什么建议我如何在不同的声明上动态更改扩展工具图标? Thanks In Advance!
提前致谢!
Well, it's there in the docs . 好吧, 它在docs中 。
declarativeContent
API can only execute a very limited number of actions instead of arbitrary code. declarativeContent
API只能执行非常有限数量的操作,而不能执行任意代码。
Thankfully for you, chrome.declarativeContent.setIcon
is an action that does exactly what you need. 幸运的是,
chrome.declarativeContent.setIcon
是一项完全chrome.declarativeContent.setIcon
您需要的操作。 Use it just like the one you're using already, except it expects a parameter. 像需要使用的参数一样使用它,只是需要一个参数。
And give that docs page a read in general. 并大致阅读该文档页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.