Skip to content

Commit 8b258a2

Browse files
committed
Open tabs next to the current one
When clicking or cmd-clicking a link in a tab, Chrome opens a new tab next to the current one, or, if many have been clicked, at the end of that "local stack". `chrome.tabs.create` opens new tabs in the last position in the window by default, so update the code to mirror the mouse-click behavior.
1 parent 9256297 commit 8b258a2

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

chrome/src/bg/background.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,19 @@ request.onload = function() {
1212
chrome.extension.onMessage.addListener(
1313
function(request, sender, sendMessage) {
1414
if(request.url) {
15-
chrome.tabs.create(request)
15+
chrome.tabs.query(
16+
{windowId: sender.tab.windowId},
17+
function(tabs) {
18+
var position = sender.tab.index;
19+
for(var i = position; i < tabs.length; i++) {
20+
if(tabs[i].openerTabId == sender.tab.id) {
21+
position = i
22+
}
23+
}
24+
request.openerTabId = sender.tab.id
25+
request.index = position + 1
26+
chrome.tabs.create(request)
27+
})
1628
} else {
1729
sendMessage(data)
1830
}

0 commit comments

Comments
 (0)