question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to switch away from closed tab if one open tab remains

See original GitHub issue

When there are two open tabs, and the current tab is closed using JavaScript, calling |switch to next tab| will time out and leave you on the closed tab. I made an acceptance test that reproduces this issue:

This test ensures we can switch back to the first tab when a previously opened second tab is closed but still our current tab.

!define HTML { {{{
<html>
<body>
First tab
</body>
</html>}}} }

!define HTML2 { {{{
<html>
<body>
<a href="javascript:window.close()">Close</a>
</body>
</html>}}} }

|script      |mock xml server setup|
|add response|${HTML}              |
|add response|${HTML2}             |
|$url=       |get mock server url  |

|script|browser test         |
|open  |$url                 |
|open  |$url      |in new tab|
|click |Close                |
|wait  |1         |seconds   |
|switch to next tab          |
|ensure|is visible|First tab |

|script|mock xml server setup|
|stop                        |

I would expect HSAC to switch to the only open tab in this case. Same goes for |switch to previous tab|.

I made a workaround for this (it was causing unnecessary failures in one of our projects):

@Override
public boolean switchToNextTab() {
    List<String> tabs = getTabHandles();
    if (tabs.size() == 1 && getCurrentTabIndex(tabs) < 0) {
        // There is only one open tab, but it is not the current one. Switch to the only open tab
        goToTab(tabs, 0);
        return true;
    } else {
        return super.switchToNextTab();
    }
}

@Override
public boolean switchToPreviousTab() {
    List<String> tabs = getTabHandles();
    if (tabs.size() == 1 && getCurrentTabIndex(tabs) < 0) {
        // There is only one open tab, but it is not the current one. Switch to the only open tab
        goToTab(tabs, 0);
        return true;
    } else {
        return super.switchToPreviousTab();
    }
}

I’m sure a more generalized solution is possible, but it may prove interesting to preserve current behavior when the current tab is closed and there are two or more open tabs. Not preserving current behavior might break a test or two.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
fhoebencommented, Apr 9, 2020

The fact that the behaviour is different whether there remains 1 tab open or multiple seems a big smell to me.

So I’m in favour of having tab switching ‘just work’ irrespective of whether the current tab is closed. I believe that is what @JessefSpecialisterren is suggesting.

0reactions
tcnhcommented, Apr 9, 2020

@fhoeben what is your take on this? A PR is very litttle work for both approaches anyway

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Delete Recently Closed Tabs on Google Chrome
Open Chrome again and repeat the process: Click the three dots, go to “Exit,” and close out again. When you reopen Chrome, the...
Read more >
Can't move tabs, can't click on different windows open in ...
About a month or so ago I noticed I was no longer able to click and drag tabs I have opened in Google...
Read more >
Quick fixes: restoring pages of tabs on Chrome - The Verge
Click on the three dots in Chrome's upper-right corner. Click on History and look under the Recently Closed heading. You should see an...
Read more >
Can I restore closed tabs after quitting Chrome? - Super User
Reopen Tab(s)​​ Yes, to some degree, however you have the combo wrong; it's Ctrl + ⇧ Shift + T . And if you...
Read more >
How to Reopen the Last Closed Tab In Any Browser
For Windows PC, hold Ctrl+Shift+T together to reopen a closed tab. If you need to recover previously opened tabs, keep tapping on the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found