You have 2 choices here:
Using two events (Not as good):
IN ADDITION to the
chrome.tabs.onUpdated
event that you're ALREADY using for your other functionality (you describe above), you could ALSO usechrome.tabs.get
method to grab thetabId
from theonActivated
's event object, then pass to a function. But, IMHO option 2 is a better one for you in this case:chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab){ //... whatever other stuff you were doing anyway }); chrome.tabs.onActivated.addListener(function(evt){ chrome.tabs.get(evt.tabId, function(tab){ alert(tab.url); //the URL you asked for in *THIS QUESTION* }); });
Use only the
onUpdated
event once (better):Do both your other stuff and what you're looking for in your question in the same event:
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab){ //... whatever other stuff you were doing anyway chrome.tabs.getSelected(null, function(tab) { alert(tab.url); //the URL you asked for in *THIS QUESTION* }); });
.
Of course, don't forget:
your manifest.json
file should have the "tabs permission":
{ "name": "My extension", ... "permissions": [ "tabs" ], ... }