0

manifest.json

{
  "manifest_version": 2,

  "name": "Project",
  "description": "Chrome Extension for sending messages",
  "version": "1.0",

  "browser_action": {
    "default_icon": "red_dot.png"
  },
  "permissions": [
    "activeTab",
    "https://ajax.googleapis.com/",
        "storage"
  ],

  "background" : {
    "scripts" : ["background.js"]
  },
    
    "content_scripts": [
      {
      "matches":["https://www.website.com/*"],
      "js":["keypress.js", "jquery.js", "js_file.js"],
            "run_at": "document_end"
        }
    ]
}

background.js

var running = false

chrome.browserAction.onClicked.addListener(function(tab) {
    if (running) {
        alert('script is running, turning off');
        chrome.browserAction.setIcon({path: "red_dot.png"})
        running = false
    } else {
        alert('script is not running, turning on');
        chrome.browserAction.setIcon({path: "green_dot.jpg"})
        running = true
    }
});

When I click on the icon, I get the popup as expected, but the icon itself isn't changing.

I'm getting this error:

Unchecked runtime.lastError: Icon invalid.

but I don't understand why. The code seems valid.

Morgan Allen
  • 3,291
  • 8
  • 62
  • 86

2 Answers2

0

use this api and carefully enter params specifically path https://developer.chrome.com/extensions/browserAction#method-setIcon

0

I had a similar issue with the invalid icon error message. The problem was in the size of the icon I wanted to use: It was more than 48px x 48px. I manually resized the icon and saved it; after that, everything worked as expected

Solution: Ensure your icon is precisely 48px x 48px in size.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Yuriy
  • 1