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?