I can set a badge text in chrome extension by below api
chrome.browserAction.setBadgeText({text: '<number_of_new_teets>'});
How can I get the badge text that I have set before ?
I can set a badge text in chrome extension by below api
chrome.browserAction.setBadgeText({text: '<number_of_new_teets>'});
How can I get the badge text that I have set before ?
Share Improve this question asked Dec 19, 2013 at 16:12 user862226user862226 1292 silver badges8 bronze badges3 Answers
Reset to default 5Use chrome.browserAction.getBadgeText
:
chrome.browserAction.getBadgeText({}, function(result) {
alert('Badge text = ' + result);
});
This method (like most of the Chrome extension API) is asynchronous, so you need to specify a callback function that receives the result.
Answer by Rob W is returning blank result
for all tabs. Adding tab.id
worked for me:
chrome.browserAction.getBadgeText({ tabId: activeTab.id }, result => {
alert('Badge text = ' + result);
});
In the Chrome extension API v3, the chrome.browserAction API has been replaced with the chrome.action API.
To set the badge text:
chrome.action.setBadgeText({text: '<number_of_new_tweets>'});
To get the badge text:
chrome.action.getBadgeText({}, function(result) {
var badgeText = result;
console.log("Badge text: " + badgeText);
});
The usage is similar to the v2 API, but note that chrome.action is used instead of chrome.browserAction in Chrome extension API v3.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745278434a4620164.html
评论列表(0条)