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 :)

Recommended Answers

All 2 Replies

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.