javascript - get badge text that set before in chrome extension - Stack Overflow

I can set a badge text in chrome extension by below apichrome.browserAction.setBadgeText({text: '&

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 badges
Add a ment  | 

3 Answers 3

Reset to default 5

Use 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信