Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Extension error: “Unchecked runtime.lastError while running browserAction.setIcon: Icon invalid."

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.

like image 342
Vishal Avatar asked Jul 19 '16 11:07

Vishal


3 Answers

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:

  • my_icon-19.png
  • my_icon-38.png

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" });
like image 169
Vishal Avatar answered Nov 20 '22 11:11

Vishal


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.

like image 24
Ogbee Avatar answered Nov 20 '22 11:11

Ogbee


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

image dimension reference

like image 1
Ayush Walekar Avatar answered Nov 20 '22 11:11

Ayush Walekar