title: Get current URL from within a chrome.contextMenus.onClicked listener
body: <p>I'm creating my first Chrome extension and I need some help. I I think everything is working except the fact that I can't get the current URL of the tab.</p>
  
  <pre><code>var menu = chrome.contextMenus.create({
      "title": "extension",
      "contexts": ["all"]
    });
  
  chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
          var siteUrl = tabs[0].url;
  });
  
  chrome.contextMenus.onClicked.addListener(function(activeTab)
  {
  
      chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
          var siteUrl = tabs[0].url;
      });
  
      var finalUrl = "http://example.com/";
  
      finalUrl += encodeURI(siteUrl);
  
      // Open the page up.
      chrome.tabs.create(
          {
              "url" : finalUrl
          }
      );
  });
  </code></pre>
  
  <p>Can anyone please help me? Thanks.</p>
  
  <p>EDIT:</p>
  
  <p>Thank you for your replies. I got it working by moving </p>
  
  <pre><code>var finalUrl = "http://example.com/";
  
      finalUrl += encodeURI(siteUrl);
  
      // Open the page up.
      chrome.tabs.create(
          {
              "url" : finalUrl
          }
  </code></pre>
  
  <p>Inside</p>
  
  <pre><code>chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
          var siteUrl = tabs[0].url;
      });
  </code></pre>