link-fixer icon indicating copy to clipboard operation
link-fixer copied to clipboard

Closing tabs jumps to first rather than next tab

Open buethastum opened this issue 4 years ago • 4 comments

Hi

Thanks for a nice and useful plugin. A minor bug (or maybe a feature request): When closing a tab after having opened a bunch, with link-fixer activated Firefox jumps back to the tab from which I've opened the other tabs, rather than to the next tab in line as is the normal behavior with the add-on activated. Would be nice to have that behavior with link-fixer on as well.

Regards, Bue

buethastum avatar Apr 08 '20 13:04 buethastum

Thanks @buethastum. I don't have time to work on this right now but PRs always welcome.

danielnixon avatar Apr 20 '20 00:04 danielnixon

I ran into this bug as well, reproduced it on both MacOS and Windows, and tracked down the cause. The problem is the openerTabId: sender.tab && sender.tab.id clause in the chrome.tabs.create() call in background-script.js; removing this clause fixes the problem. Apparently setting openerTabId causes all tabs that are opened to return to the originating tab when they're closed rather than returning to the next most-recently opened tab (as happens when you use vanilla Firefox without the extension).

I don't have enough familiarity with the relevant APIs to know why this clause was included or what side effects removing it might have (though I haven't run into any problems in my own testing), so I won't do a PR, but as I say the fix is extremely simple. I've included a patch below, and please feel free to roll a change like this into the official extension if you believe it won't cause any problems.

Thanks for the great extension!

diff --git a/background-script.js b/background-script.js
index a9b19fe..874317b 100644
--- a/background-script.js
+++ b/background-script.js
@@ -179,7 +179,7 @@ chrome.runtime.getPlatformInfo((info) => {
                   chrome.tabs.create({
                     url: message.url,
                     active: active,
-                    openerTabId: sender.tab && sender.tab.id,
+//                    openerTabId: sender.tab && sender.tab.id,
                     index: newTabIndex,
                   });
                 });

jcaruso avatar Jul 25 '22 20:07 jcaruso

By the way, these are the steps to reproduce the bug:

  1. Open a web page (aka tab 1)
  2. Open two tabs (tabs 2 and 3) from tab 1 using ctrl-click or cmd-click
  3. Navigate to tab 3 via keyboard or mouse
  4. Close tab 3. The focus will move back to tab 1 rather than to tab 2 (and note that it doesn't matter if you navigated through tab 2 to get to tab 3 in the previous step -- the focus will still return to tab 1).

If you disable the link-fixer extension and repeat this test, the focus will move to tab 2 in step 4.

This bug only occurs with Firefox, by the way -- link-fixer for Chrome appears to work as expected.

jcaruso avatar Jul 25 '22 21:07 jcaruso

After some quick testing, it seems that passing undefined instead of an actual tab index to the chrome.tabs.create (https://github.com/danielnixon/link-fixer/blob/0153cbff4195028e1a385e00aa3c8b0f387965cd/background-script.js#L183) works as expected for me in Firefox 116.0.2 on Windows (same behaviour with addon and without addon).

Same result occurs if the index key is not passed at all.

If this is only an issue on Firefox, we might leave the old newTabIndex for Chrome users and set it to undefined in Firefox.

zznidar avatar Aug 20 '23 12:08 zznidar