Skip to content
Advertisement

Chrome extension: Get last used tab

I’m trying to create a simple plugin for Google Chrome. One of the functions would be a return to the last used tab, but I don’t know how to do it.

So, is there any way to get the last used tab?

Advertisement

Answer

You could try adding a hook into the onSelected event of the tabs and just saving that variable… soemthing like this:

var curTabID = 0;
var curWinID = 0;

chrome.tabs.onSelectionChanged.addListener(function(tabId, selectInfo) {
   curTabID = tabId;
   curWinID = selectInfo.windowId;
});

Then you have the window id and the tab id at all times.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement