title: Chrome Extension to fetch URL of current tab and open new tab based on re-writing URL
body: <p>I actually want to use this with a more complex re-write of the URL but for simplicity right now I want to accomplish something more basic.  So if I'm on <a href="https://www.google.com" rel="nofollow">https://www.google.com</a> and click the button for my extension, I want it open a new tab with <a href="http://www.google.com/images" rel="nofollow">http://www.google.com/images</a></p>
  
  <p>I found separate questions about fetching the URL and opening a new tab, but I haven't been able to find anything about combining the two.</p>
  
  <p>This is what I have right now:</p>
  
  <p>manifest.json:</p>
  
  <pre><code>{
    "manifest_version": 2,
  
    "name": "Rewrite",
    "version": "0.1",
  
    "browser_action": {
      "default_icon": "icon.png"
    },
    "background": {
      "scripts": ["background.js"],
      "persistent": false
    },
    "permissions": ["https://*/*", "http://*/*", "tabs"]
  }
  </code></pre>
  
  <p>background.js:</p>
  
  <pre><code>var currentURL;
  
  chrome.tabs.query({ currentWindow: true, active: true }, function (tabs) {
    currentURL = tabs[0];
  });
  
  chrome.browserAction.onClicked.addListener(function(activeTab) {
      var newURL = currentURL + "/images";
      chrome.tabs.create({ url: newURL });
  });
  </code></pre>
  
  <p>I've tried various forms of this such as having the chrome.browserAction.onClicked.addListener block nested inside of the chrome.tabs.query block and vice versa but none seem to work.</p>
  
  <p>With the current version, the tab opens but the URL is chrome-extension://bffolfmjagnpglbmjkgajodjlfpekaeo/[object%20Object]/images with a "webpage is not found" error.</p>