Skip to content

Instantly share code, notes, and snippets.

@botmtl
Forked from danharper/background.js
Last active September 27, 2016 06:38
Show Gist options
  • Save botmtl/214fd6e6f0e7522c10eafe85bd45a0d5 to your computer and use it in GitHub Desktop.
Save botmtl/214fd6e6f0e7522c10eafe85bd45a0d5 to your computer and use it in GitHub Desktop.
Bare minimum Chrome extension to inject a JS file into the given page when you click on the browser action icon. The script then inserts a new div into the DOM.
// this is the background code...
// listen for our browerAction to be clicked
chrome.browserAction.onClicked.addListener(function (tab) {
// for the current tab, inject the "inject.js" file & execute it
chrome.tabs.executeScript(tab.ib, {
file: 'inject.js'
});
});
// this is the code which will be injected into a given page...
(function() {
document.body.style.backgroundColor="red";
})();
{
"name": "Injecta",
"version": "0.0.1",
"manifest_version": 2,
"description": "Injecting stuff",
"homepage_url": "http://danharper.me",
"background": {
"scripts": [
"background.js"
],
"persistent": true
},
"browser_action": {
"default_title": "Inject!"
},
"permissions": [
"activeTab"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment