0

I know that the manifest file allow only 1 icon, but can I update the icon on different urls?

For example show a red icon in Google, and on youtube it has another icon. Is that possible? Can I update the icon in js, if not in the manifest file?

codeMagic
  • 44,549
  • 13
  • 77
  • 93
Thian Kian Phin
  • 921
  • 3
  • 13
  • 25
  • Have you tried [reading the documentation](https://developer.chrome.com/extensions/pageAction)? – Xan Aug 19 '14 at 15:14
  • @Xan couldn;'t find what I'm looking for. – Thian Kian Phin Aug 19 '14 at 15:16
  • @ThianKianPhin Did Xan's answer below work for you? If so, it should be marked as correct. IMHO it's the only way, you need to use the setIcon-method; you cannot change the manifest itself, cause that's fixed once the extension is loaded by the toolbar. – Mathias Conradt Mar 10 '16 at 13:56

2 Answers2

2

This is easy to find in the documentation:

chrome.pageAction.setIcon(object details, function callback)

Sets the icon for the page action. The icon can be specified either as the path to an image file or as the pixel data from a canvas element, or as dictionary of either one of those. Either the path or the imageData property must be specified.

You need to pass a Tab ID to it, e.g.

chrome.pageAction.setIcon({tabId: id, path: 'icon.png'});

For more options, see the above documentation link.

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

The answers given are correct, a Chrome extension is allowed one of either a PageAction button or a BrowserAction button.

But that is not true for Firefox extensions, which allow one page_ction button (a.k.a. address bar button) and one browser_action button (a.k.a. toolbar button).

tst
  • 479
  • 4
  • 7