chrome.browserAction.setIcon not doing anything


I am making a chrome extension, and the extension has two modes: always on (alwaysOn), or only when the user clicks it (onClick). I want to change the icon to be blue or red depending on the user's mode, so they can see it at a glance. However, after adding the chrome.browserAction.setIcon() line, the icon still doesn't change when it needs to. It just stays on the default logo.

Here is my background.js:

// Get the behavior of the plugin; the default is set to "onClick", the other option is "alwaysOn" chrome.storage.sync.get({ extensionBehavior: 'onClick' }, function(items) { if(items.extensionBehavior == 'onClick'){ chrome.browserAction.setIcon({path: "blue-logo.png"}); chrome.browserAction.onClicked.addListener(function() { // When the extension icon is clicked, send a message to the content script chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { chrome.tabs.sendMessage(tabs[0].id, {"message": tabs[0].url}, function(response){}); }); }); } else { chrome.browserAction.setIcon({path: "red-logo.png"}); chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { if (changeInfo.status == 'complete') { // When the HTML loads, send a message to the content script chrome.tabs.query({active: true, currentWindow: true}, function(tabs){ chrome.tabs.sendMessage(tabs[0].id, {"message": tabs[0].url}, function(response){}); }); } }); } });

Everything else runs perfectly, and the console.log() doesn't show any errors. Is there any reason javascript would be "skipping over" these particular lines of code? ("These particular lines of code" being chrome.browserAction.setIcon({path: "blue-logo.png"}); and chrome.browserAction.setIcon({path: "red-logo.png"});) The images in question are in the same folder as my background.js, content_script.js, etc. so I'm not sure if the path is just being read wrong or what.

EDIT: I opened the console and I get the message "Unchecked runtime.lastError while running browserAction.setIcon: Icon invalid." What does this mean? If I specify the full path starting from C:\Users...\blue-logo" I get the error message could not find.


I don't know why, but you can't use setIcon function with icon bigger than 190px width and height.

Bug or feature i don't know. Documentation don't tell us...

The strange thing is, you can use the same icon in the manifest.json file.


Your code is fine!

For it to work, Icon dimensions should 16x16, 48x48 or 128x128 px, as recommended on the official documentation:

<a href="https://developer.chrome.com/extensions/manifest/icons" rel="nofollow">https://developer.chrome.com/extensions/manifest/icons</a>


  • Access QML StackView from a control
  • Chrome extension modify newtab page body?
  • Open a local .html on extension mouse click
  • chrome.browserAction.setIcon not doing anything
  • Setting object type property in QML from C++
  • How can I get the width/height of a loaded swf's stage in AS2?
  • How to implement collision detection on nodes which are in StackPane (in JavaFX)?
  • InfoWindow showing in wrong place
  • Chrome extension update notification
  • Pubnub subscribe stops receiving messages after some time
  • Connecting Couchbase sync adapter to couchdb server
  • gulp: passing dependent task return stream as parameter
  • readyRead() signal of QextSerialPort (QIODevice) is not being called fast enough
  • Entity Framework ObjectContext: Concurrency
  • change color of jstree node
  • java.lang.IndexOutOfBoundsException occuring on ArrayList
  • Subclassing QGraphicsItem prevents me from being able to use itemAt() on a QGraphicsScene/View
  • Selenium to click on a javascript button corresponding to a text
  • Detect when Facebook like button is clicked
  • Retrieve list of sent friend requests from friend_request FQL table
  • How to install a .deb file on a jailbroken iphone programmatically?
  • NHibernate Validation Localization with S#arp Architecture
  • Using variable in a value field in jMeter
  • DomPDF {PAGE_NUM} not on first page
  • Update CALayer sublayers immediately
  • How can I send an e-mail from a vbs script
  • Javascript simulate pressing enter in input box
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • Align navbar back button on right side
  • DotNetZip - Calculate final zip size before calling Save(stream)
  • Accessing IRQ description array within a module and displaying action names
  • Updating server-side rendering client-side
  • Importing jscolor library in angular 2
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • How to pass list parameters for each object using Spring MVC?
  • A cron job substitute?
  • Load html files in TinyMce
  • Free memory of cv::Mat loaded using FileStorage API
  • Getting Messege Twice Using IMvxMessenger
  • sending mail using smtp is too slow