Calling chrome.browserAction.setIcon from content script the way it is done in background script
I am making an extension for chrome. It fetches data from webpages and emails it via local email client. I have a toolbar button which user has to click to invoke the script. My script works for a few selected urls. I want my toolbar button to change icon based on whether the url is among our list or not. For example for site1 it should be redicon.png and for site2 it should be blueicon.png. I can change button icon using chrome.browserAction.setIcon. But the problem is that this API does not work in content script. It works fine in the background.js file but not in content.js. Kindly tell me how to achieve this. I know using pageAction instead would do the trick but my client requirement is that the toolbar icon should change rather than appear and disappear.
What you need to read about is message passing. You are right, content scripts have limited chrome API. However, you can contact background page from content script and tell it to execute anything from chrome API for you. First, you need to create a listener on a background page that will be waiting for messages and then send a message from a content script.
Chrome Extension - make a ribbon
Minimize developer tools window while debugging a chrome extension
Getting emulated mobile view of a temporarily changed html page
Google Chrome extension communicate with Panel
Chrome Extension error: “Unchecked runtime.lastError while running browserAction.setIcon: Icon invalid."
Listen to Keyboard and Mouse Chrome Hosted App
Is it possible to catch requests from another extension?
getSelection fails on top commercial websites, how to unblock?
Chrome extension to capture video of last few minutes of active tab
when I click the input autocomplete suggestion,the extension popup disappears[close] [duplicate]
Secure the communication between Chrome extension and the sever
Are these permissions mandatory in my Chrome extension?
How to catch/listen for notification with chrome extension?
Simulate Click on Chromebook
How can I store data on the backend script and use it in the content script of my chrome extension?