I am trying to create a Google Chrome extension. I have the code actually injecting but all I am getting is alert dialog boxes.
manifest.json:
{
  "name":"Xpress Test Extension",
  "manifest_version": 2,
  "version":"0.2",
  "icons": {
    "16": "icon_16.png",      
    "20": "icon_20.png",
    "128": "icon_128.png"
  },
  "background": { 
    "scripts":  ["background.js","content_script.js"]
  },
  "browser_action": {
    "default_popup": "popup.html",
    "default_icon": "icon_20.png"
  },
  "content_scripts": [
    { 
      "matches": ["https://stackoverflow.com/*"],
      "js" : [ "content_script.js","script.js" ]
    }
  ],
  "content_security_policy": "default-src 'self'",
  "permissions": [
    "tabs",
    "https://stackoverflow.com/*",
    "contextMenus",     "unlimitedStorage"
  ],
  "web_accessible_resources": [
    "icon_20.png",
    "icon_128.png",
    "background.html",
    "content_script.js",
    "popup.html",
    "popup.js",
    "script.js",
    "background.js"
  ]
}
content_script.js (stolen of course...):
alert('content script!');
var port = chrome.extension.connect();
var rootnode=document.getElementById('topbar');
if (null==rootnode) {
  alert ('could not find div#id topbar');
} else {
  rootnode.addEventListener("click", function() {
    var s = document.createElement('script');
    s.src = chrome.extension.getURL("script.js");
    s.onload = function() {
      this.parentNode.removeChild(this);
    };
    (document.head||document.documentElement).appendChild(s);
    alert( "Hello");
  }, false);
}
script.js  (brazenly copied from sample code):
 // JS script injection, so that we can read the JS class 'InternalJSVariable'
 var postFriendMap = function() {
 var textarea = document.getElementById('transfer-dom-area');
 textarea.value = JSON.stringify(InternalJSVariable);
 };
 // Create a dummy textarea DOM.
 var textarea = document.createElement('textarea');
 textarea.setAttribute('id', 'transfer-dom-area');
 textarea.style.display = 'none';
 document.body.appendChild(textarea);
 // Start injecting the JS script.
 var script = document.createElement('script');
 script.appendChild(document.createTextNode('(' + postFriendMap + ')();'));
 document.body.appendChild(script);
 alert('injection');
 var textNode=document.createTextNode("CLICK ME");
 var buttonElem=  document.createElement( "button");
 buttonElem.setAttribute("id","extraButton001");
 buttonElem.appendChild(textNode);
 document.getElementById('logo').appendChild(buttonElem);
From my background.js (more theft of sample):
function genericOnClick(info, tab) {
  console.log("item " + info.menuItemId + " was clicked");
  console.log("info: " + JSON.stringify(info));
  console.log("tab: " + JSON.stringify(tab));
  chrome.tabs.executeScript(null, {file: "content_script.js"});
  console.log('sent to content script...');
}
// Create one test item for each context type.
var contexts = ["page","selection","link","editable","image","video",
             "audio"];
for (var i = 0; i < contexts.length; i++) {
   var context = contexts[i];
   var title = "Test '" + context + "' menu item";
   var id = chrome.contextMenus.create({"title": title, "contexts":[context],
                                    "onclick": genericOnClick});
   console.log("'" + context + "' item:" + id);    
}
// Create a parent item and two children.
var parent = chrome.contextMenus.create({"title": "Test parent item"});
var child1 = chrome.contextMenus.create(
    {"title": "Child 1", "parentId": parent, "onclick": genericOnClick});
var child2 = chrome.contextMenus.create(
    {"title": "Child 2", "parentId": parent, "onclick": genericOnClick});
console.log("parent:" + parent + " child1:" + child1 + " child2:" + child2);
- http://code.google.com/chrome/extensions/manifestVersion.html
- Insert code into the page context using a content script
- Chrome extension - Message Passing
- http://code.google.com/chrome/extensions/examples/api/contextMenus/basic/sample.js
- Google Chrome Extension - Accessing The DOM
- http://code.google.com/chrome/extensions/contentSecurityPolicy.html#H2-3
 
    