google-chrome-extension


How can I trigger a content script to run when I click the popup icon of a Google Chrome extension?


Building my first Chrome app and was wondering how to run myscript.js only when icon.png is clicked. Now it just runs whenever a page loads.
Here is my manifest.json file:
{
"name": "My extension",
"version": "1.0",
"background_page": "background.html",
"permissions": [
"tabs", "http://*/*"
],
"content_scripts": [
{
"matches": ["http://*/*"],
"js": ["myscript.js"],
"run_at": "document_end"
}
],
"browser_action": {
"default_icon": "icon.png"
}
}
If you don't need the content script any other time except when the button is pressed, see the Chrome docs on programmatic injection to use executeScript to inject scripts on the fly.
You'll want to look into message passing. Basically the set up is:
Make another content script that listens for instructions
When the popup is clicked, fire instructions off to the content script
Content script does what it needs to do, passes back something that says it's done
Popup knows the work has been done
This is done so content scripts and background scripts' (or popups) are isolated and secure.

Related Links

Chrome extension custom payment solution in Pakistan?
How to get support tab for Google Chrome extension
How to Log to Console from Chrome Extension?
Chrome Extension - Detecting New Posts on a 4chan thread
Chrome Extension Template (Regex Filter) needed
Tricking a javascript code to think it has a focused window?
my extension keep getting rejected and i don't know why
Can I use an alias to release a chrome extension?
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?

Categories

HOME
heroku
push-notification
kde
path-finding
platform-builder
sd-card
cplex
jsp-tags
yahoo-oauth
analysis
twitter-bootstrap-4
sqlite3
gps
umd
angular-ui-bootstrap
spring-kafka
offline
handsontable
quickbooks
static-libraries
zebra-printers
quickfix
iolanguage
http-status-code-504
interop
code-review
jtextfield
zapier
csrf-protection
tapestry
kudan
bootstrap-tour
h2db
cas
kannel
neo4j-spatial
ping
vision
file-rename
newline
flink-streaming
r-raster
microsoft-chart-controls
preg-match
nameservers
google-sites-2016
winrt-xaml-toolkit
grails-3.1
pim
commit
form-data
normal-distribution
host
plsql-psp
gesture
g-code
flashair
sas-jmp
avconv
smartcontracts
fancybox-2
integrity
forever
tactic
diagnostics
pg-dump
libusb-win32
android-cursor
qtwebview
pdfclown
gcsfuse
mediaelement
storekit
make-install
captivenetwork
two-factor-authentication
prerequisites
google-places
ruby-2.2
dukescript
android-listview
ibaction
formatjs
ng-animate
codeigniter-routing
titanium-modules
rtmfp
bundles
mysqltuner
xsockets.net
tidy
dataadapter
spring-validator
pygit2
anonymous-methods
typoscript2
bitsharp
quickdialog
cisco-jtapi
boost-filesystem
qt-jambi
propagation
android-sdk-2.1
mysql-error-1005
datareader
paster
vc90
ext3
ncqrs
nintendo-ds
private-members
data-acquisition

Resources

Encrypt Message