Hi there ! I'm building my first GC extension, and I am having a problem using this function.

I would like to get the url of the current tab, and to do so (after some google research, of course), I use the chrome.tabs.getSelected() function. Here it is in my code :

socket.onopen = function(msg){ log("Welcome - status " + this.readyState); 
chrome.tabs.getSelected(null, function(tab){ sendUrl(tab.url); }); };

function sendUrl(tabUrl)
 socket.send("#URL#"+ tabUrl);

The socket.open is a listener for the Websocket API I use in my extension. The log function print the status of the socket (1, which means it's OPEN or connected and ready to communicate, according to the Websocket API), but the chrome.tabs.getSelected() function do not seems to work, as the server do not receive anything (the socket is not the problem here, I tried to send a test message with socket.send() instead of chrome.tabs.getSelected() and the server received it).

I put the permissions: ["tabs"] into the manifest.json so I can use this function.

So I don't know what I am doing wrong here ? I also tried to put chrome.tab.getSelected() elsewhere in the code, but it is still not working.

Any help is welcome :)

8 Years
Discussion Span
Last Post by colon3l

chrome.tabs.getSelected(null, function(tab){ sendUrl(tab.url); } )

You might try replacing sendUrl(tab.url); with var tmp = tab.url;sendUrl(tmp); .

It that doesn't work, at least it will give you a checkpoint to test the return.


Thx for the answer, I actually managed to resolve this problem by putting all this code into the background page :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.