views:

133

answers:

1

Hi, i'm building a google chrome extension, and i'm trying to get the selected window in a popup. (i'm talking about the popup that shows when you click in the extesion icon).

I try to use the documentation, but i didn't get it well. I tryied to use:

chrome.windows.getCurrent(function(w) {
    chrome.windows.get(w.id,
    function (response){
        alert(response.location.href);
    });
});

But didn't work. Any ideas?

Thanks (sorry if the english is bad).

A: 

1) have you added the "tabs" permission to the manifest?

{
  "name": "My extension",
  ...
  "permissions": ["tabs"],
  ...
}

2) It also looks like you should be using the tabs API and not the windows API if you want to know the current URL of the selected tab in the current Window

chrome.windows.getCurrent(function(w) {
    chrome.tabs.getSelected(w.id,
    function (response){
        alert(response.url);
    });
});
Kinlan