Yashwant Kumar Sahu
Yashwant Kumar Sahu

Reputation: 3386

how I can change default icon in chrome extension?

Here I am working with chrome extension development.

my manifest.json page as show

{
"name": "DemoExtension",
  "version": "1.0",
  "description": "Official addon from demeo",
  "browser_action": {
    "default_icon": "star-on.png",
    "popup": "shopcmp.htm"  
  },
  "permissions": [
    "tabs"    
  ],
  "background_page": "background.html"   
}

Here I want to change my default icon image at runtime.

Upvotes: 25

Views: 44027

Answers (5)

Joel Grayson
Joel Grayson

Reputation: 197

Note: if you are referencing an image within your extension folder, use absolute paths. For example, /icon.png, not icon.png, or you will trigger a Failed to fetch error.

Upvotes: 3

momaji
momaji

Reputation: 211

with the new manifest v3 the standard for changing an icon at runtime is now

chrome.action.setIcon()

Upvotes: 8

Nathan Bertram
Nathan Bertram

Reputation: 1099

To change the default chrome extension pragmatically you can do:

chrome.browserAction.setIcon({ path: "my-icon.png" });

or for custom sizes:

chrome.browserAction.setIcon({
  path: {
    19: "my-icon19.png"
  }
});

Full docs: https://developer.chrome.com/docs/extensions/reference/browserAction/#method-setIcon

Upvotes: 21

gaowhen
gaowhen

Reputation: 409

if you want every page has its own icon status, use chrome.pageAction.

Upvotes: 0

Digital Plane
Digital Plane

Reputation: 38274

If you want to change the browser action default icon, just change

"browser_action": {
  "default_icon": "star-on.png", //<--this line: change "star-on.png" to the icon you want
  "popup": "shopcmp.htm"  
},

That line indicates the default icon on first load of the extension.
To change the icon in code, call chrome.browserAction.setIcon(details).

If you want to change the extension icon (the icons that shows during installation, in the Chrome Web Store, in the extension management page, and as a favicon), add an icons property to your manifest.json file.

Upvotes: 23

Related Questions