Skip to content

Focus Randomly Stays on Old Tab When Opening New Tabs with Redirects #2761

@winst0niuss

Description

@winst0niuss

Description

When clicking a button/link that opens a new tab (with target="_blank"), which then performs multiple redirects (e.g., authentication flow), focus does not consistently switch to the newly opened tab.

The new tab opens successfully in the background, but focus randomly remains on the old tab instead of switching to the new one. This behavior is intermittent - sometimes it works correctly, sometimes it doesn't.

Steps to Reproduce

  1. Have a page with a link/button that opens a new tab
  2. The opened tab performs multiple redirects (e.g., OAuth/SSO authentication flow with 3-5 redirects)
  3. Observe which tab has focus after the redirects complete

Expected Behavior

Focus should consistently switch to the newly opened tab after it finishes loading (including all redirects).

Actual Behavior

Focus randomly stays on the original tab. The new tab opens in the background, but doesn't become the active tab. This happens inconsistently - approximately 40-60% of the time in my tests.

Environment

  • Taiko version: 1.4.6
  • Node.js version: 20.x
  • OS: Windows Server 2016
  • Browser: Chrome for testing 140.0.7339.82 (bundled with Taiko)

Additional Context

  • The issue is more pronounced when the new tab has multiple redirects (authentication flows)
  • With simple pages (no redirects), the issue still occurs but less frequently
  • Using switchTo() after the click is a workaround, but it's not reliable because timing is difficult to predict with redirects

Regression Information

  • Taiko 1.4.4 with custom Chromium 120.0.6099.0 (dev build): ✅ Issue did not occur
  • Taiko 1.4.6 with bundled browser (Chrome 140.0.7339.82): ❌ Issue became critical and occurs frequently (40-60% of the time)

Sample Code

await openBrowser();
await goto('https://example.com');

// Click button that opens new tab with auth redirects
await click(button('Login in New Tab'));

// Expected: Focus is on the new tab
// Actual: Focus randomly stays on old tab

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions