google-chrome-extension


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.

Related Links

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]
RequireJS not loaing JavaScript in Firefox WebExtensions add-on
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?

Categories

HOME
ibm-bluemix
ionic-framework
variables
comparison
sd-card
cmd
tizen-web-app
datastax-java-driver
adfs
windows-azure-storage
moonmail
text-rendering
contextmenu
dbext
java-3d
jasonette
crosstab
opennlp
qhull
wpfdatagrid
greendao
publish
libuv
fabric8
semantic-versioning
catel
perlin-noise
asset-pipeline
temporary-files
graphenedb
sfdc
google-closure
turbogears
sencha-touch-2.3
executenonquery
filepicker
worksheet
tizen-native-app
togetherjs
mplayer
setter
np-complete
boost-preprocessor
smart-table
grails-tomcat-plugin
intrusion-detection
multi-level
mikroc
qpid
lttng
python-stackless
hexdump
ios4
tform
historian
freedesktop.org
maven-tomcat-plugin
reactive-banana
sdhc
collapse
ruby-2.2
content-length
iis-arr
quicklisp
myo
unity3d-gui
kineticjs
angularjs-ng-click
mdt
responsive-slides
typeof
wp-query
inbox
spring-io
dataservice
buster.js
dataadapter
jquery-mobile-dialog
wsdl-2.0
bitsharp
armcc
javaspaces
twrequest
boost-filesystem
gamequery
fixed-width
privilege
mediarss
dbisam
django-notification

Resources

Encrypt Message