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,229
  • 13
  • 74
  • 91
Thian Kian Phin
  • 861
  • 3
  • 11
  • 24
  • 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

1 Answers1

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
  • 71,217
  • 14
  • 165
  • 189