1

I wrote a chrome extension, and it works properly.

My extension is nothing more than a counter. At the moment, I have to click on the extension icon to see the counter result.

I'd like to have it printed in the bar instead of having to click on an icon to see the result. Is it possible?

I wasn't able to find anything on that, so any help will be really appreciated.

Sorry for not posting here any code, but i don't really think it's necessary for this question.

thanks

wOxxOm
  • 65,848
  • 11
  • 132
  • 136
Nick
  • 13,493
  • 8
  • 51
  • 98

1 Answers1

1

The easiest way to do it is to use badges next to the icon.

That's how they look: Browser action badge

To set a badge for your extension's icon (assuming it's a Browser Action):

chrome.browserAction.setBadgeText({text: "1"});
chrome.browserAction.setBadgeBackgroundColor({color: [255, 255, 0, 255]}); // RGBA array
chrome.browserAction.setBadgeBackgroundColor({color: "#FFFF00"}); // CSS value

This can also be done per-tab; see the documentation for more info.


If you really want to change your icon, you can draw whatever you want on a <canvas> element and update your icon with chrome.browserAction.setIcon() using imageData format. Here's an example.

Community
  • 1
  • 1
Xan
  • 74,770
  • 16
  • 179
  • 206