I have an extension that was originally made awhile back with manifest version 1. It uses a chrome.tabs.getSelected
and chrome.tabs.getAllInWindow
which were deprecated in Chrome 33. We're practically on Chrome 54 now, so I wanted to make it newer. The current permission in the manifest is tabs
. I heard this may have to do with it being asynchronous.
The extension as it exists is a button that closes ALL tabs to the left of the selected or active tab.
function closeLeftTabs() {
var curTab;
chrome.tabs.getSelected( null , function(tab) {
curTab=tab;
});
chrome.tabs.getAllInWindow(null,function(tabs) {
for (var i = 0; i < tabs.length; i++) {
if (tabs[i].index<curTab.index){
chrome.tabs.remove(tabs[i].id, null);
}
}
});
}
chrome.browserAction.onClicked.addListener(function(tab) {
closeLeftTabs();
});
I'm updating it to ignore pinned tabs (not close them) using the queryInfo parameter of chrome.tabs.query
, but the JavaScript no longer works when pressing the button. Here's the idea I have so far.
function closeLeftTabs() {
var curTab;
chrome.tabs.query({highlighted: true}, function(tab) {
curTab=tab;
});
chrome.tabs.query({pinned: false},function(tabs) {
for (var i = 0; i < tabs.length; i++) {
if (tabs[i].index<curTab.index){
chrome.tabs.remove(tabs[i].id, null);
}
}
});
}
chrome.browserAction.onClicked.addListener(function(tab) {
closeLeftTabs();
});
Clicking the button with the above code now seems to do nothing. I don't have much JavaScript experience and I haven't used any of the new parameters yet. I also experimented with currentWindow
and lastFocusedWindow
booleans and nothing changed, so I can't identify the root of the problem.