Skip to content

Instantly share code, notes, and snippets.

Forked from danharper/background.js
Created August 9, 2016 21:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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() {
// just place a div at top right
var div = document.createElement('div'); = 'fixed'; = 0; = 0;
div.textContent = 'Injected!';
alert('inserted self... giggity');
"name": "Injecta",
"version": "0.0.1",
"manifest_version": 2,
"description": "Injecting stuff",
"homepage_url": "",
"background": {
"scripts": [
"persistent": true
"browser_action": {
"default_title": "Inject!"
"permissions": [
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment