how to get active tab instantly in Chrome Extension -
i working on chrome extension. possible active tab info in current window instantly rather using "chrome.tabs.query()"?
if have timing constraint need active tab (not async) can maintain reference active tab listening active tab changes chrome.tabs.onactivated e.g.
var activetab; function updateactive(tab) { activetab = tab; } function onactivated(info) { chrome.tabs.get(info.tabid, updateactive); } function onupdated(info, tab) { if (tab.active) updateactive(tab); } chrome.tabs.query({active: true, lastfocusedwindow: true}, function(tabs) { updateactive(tabs[0]); chrome.tabs.onactivated.addlistener(onactivated); chrome.tabs.onupdated.addlistener(onupdated); });
then when want tab use activetab
.
note: handling multiple windows left excercise reader. see chrome.windows.onfocuschanged
Comments
Post a Comment