title: Trivial Chrome pageAction extension not working
body: <p>I'm trying to write a trivial Chrome pageAction extension to change all anchors on a page from one domain to another... but I can't quite seem to get it to work, and I'm having trouble debugging it.</p>
  
  <p>Am I misunderstanding how this kind of extension needs to be built? Or am I just misusing the API?</p>
  
  <p><strong>manifest.json</strong>:</p>
  
  <pre><code>{
    "name": "theirs2ours",
    "version": "1.0",
    "description": "Changes all 'their' URLs to 'our' URLs.",
    "background_page": "background.html",
    "permissions": [
      "tabs"
    ],
    "page_action": {
      "default_icon": "cookie.png",
      "default_title": "theirs2ours"
    },
    "content_scripts": [
      {
        "matches": ["http://*/*"],
        "js": ["content.js"]
      }
    ]
  }
  </code></pre>
  
  <p><strong>background.html</strong>:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script type='text/javascript'&gt;
  
  chrome.tabs.onSelectionChanged.addListener(function(tabId) {
    chrome.pageAction.show(tabId);
  });
  
  chrome.tabs.getSelected(null, function(tab) {
    chrome.pageAction.show(tab.id);
  });
  
  chrome.pageAction.onClicked.addListener(function(tab) {
      chrome.tabs.sendRequest(tab.id, {}, null);
  });
  
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>content.js</strong>:</p>
  
  <pre><code>var transform = function() {
    var theirs = 'http://www.yourdomain.com';
    var ours = 'http://sf.ourdomain.com';
    var anchors = document.getElementsByTagName('a');
    for (var a in anchors) {
      var link = anchors[a];
      var href = link.href;
      if (href.indexOf('/') == 0) link.href = ours + href;
      else if (href.indexOf(theirs) == 0) link.href = href.replace(theirs, ours);
    }
  };
  
  chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
    transform();
  });
  </code></pre>