I was trying to change Chrome extension icon dynamically by following this documentation.
Unfortunately, it is not working with the following code:
chrome.browserAction.setIcon({path: 'my_icon.png'});
In console, it is failing with following error:
Unchecked runtime.lastError while running browserAction.setIcon: Icon invalid.
After reading elsewhere on the web, I found that we need to specify images with size either (or both) of 19x19 px or 38x38 px.
So I resized my icon image, and made 2 copies of it as follows:
Now when I tried the following code, it worked as expected:
chrome.browserAction.setIcon({ path: { "19": "/images/my_icon-19.png",
"38": "/images/my_icon-38.png" } });
You do not need both of the versions to make it work, so following would work as well:
chrome.browserAction.setIcon({ path: "/images/my_icon-38.png" });
I had this same error. I fixed it after I resized the icon much lot smaller. My original icon was 200px by 200px and the one that worked was 100px by 100px.
I had similar issue, resizing it with 128px*128px, with resolution of 72px/inches, worked for me.
Prior to that I tried with 512px and 256px proportions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With