Skip to content

fix(devicelab): connecting to Chrome leaves the tabs that were open before - #281

Open
luka-vladika-happening-xyz wants to merge 1 commit into
devicelab-dev:mainfrom
luka-vladika-happening-xyz:fix/devicelab-browser-closes-only-its-own-tabs-2
Open

luka-vladika-happening-xyz wants to merge 1 commit into
devicelab-dev:mainfrom
luka-vladika-happening-xyz:fix/devicelab-browser-closes-only-its-own-tabs-2

Conversation

@luka-vladika-happening-xyz

Copy link
Copy Markdown
Contributor

Summary

In browser mode on Android, every connect to Chrome's DevTools closed every page target but the one the runner keeps (closeOtherTabs, added in cba8e61 so that the tabs openLink opens do not pile up). On a phone a person also uses, the first connect closed all of their open tabs, with no option to turn it off. The manager now remembers the page targets Chrome lists the first time the runner reads them and never closes those; later connects close the other page targets but the kept one, as before, so the runner's own openLink tabs are still cleaned up, but for up to two a run (below).

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)

Changes Made

  • webViewManager.preexistingTabs: the page targets of the first /json read, kept across disconnect and cleanup (which openLink goes through at every link).
  • closeOtherTabs: the first call only remembers those targets; every later call closes the page targets that are neither remembered nor kept.
  • A run can leave up to two tabs of its own open: the page kept at its first look (one of the remembered ones, when its first openLink came before its first connect) and the page kept at its last connect, which upstream also left; upstream left that one only, and the next run closed it, where a later run on the same phone now takes both for tabs that were there before. A tab opened during the run by someone else is closed at the next connect, as today.

Related Issues

None filed.

Testing

  • Tests pass locally (go test -race ./pkg/driver/devicelab/)
  • Linting passes (golangci-lint v2.13.2: 0 issues)
  • Added tests for new functionality
  • Tested manually with sample flows

TestCloseOtherTabsLeavesTabsOpenBeforeTheFirstLook runs a fake DevTools endpoint on a Unix socket and records the tabs it is asked to close: the first connect (three tabs that were open and the one an openLink opened) closes nothing, then after a disconnect and a cleanup, a later connect closes only the tab opened after the first look. On main the first connect closes the three tabs that were open.

Manually, on an Android 16 emulator's Chrome (this commit in a build carrying other, unrelated fixes): three tabs opened before the run stayed open after a flow that opens a link and asserts on it, where main closed them; a second run left one more tab of its own, and a run of three links closed only its own middle one.

Checklist

  • Code follows project style guidelines
  • Self-reviewed the code
  • Added/updated documentation as needed
  • No breaking changes (or documented if breaking)
  • CHANGELOG.md updated (for notable changes): left to you when merging

…efore

Each connect to Chrome's DevTools closed every page target but the one it
kept (closeOtherTabs, added so that openLink's new tabs do not pile up).
On a phone in use that closed all of its owner's tabs at the runner's
first connect, with no option to turn it off.

The manager now remembers the page targets Chrome listed the first time
it read them, and never closes those: they are tabs the runner did not
open. Later connects close the other page targets but the kept one, as
before, so the tabs openLink opens after that first look are still
cleaned up. The set survives openLink's disconnect and a cleanup.

A runner process can leave up to two tabs of its own open: the page kept
at its first look, when an openLink came before its first connect (it is
one of the remembered ones), and the page kept at its last connect, which
upstream also left. Upstream left that one only, and the next process
closed it; now the next process takes both for tabs that were there
before.

A test with a fake DevTools endpoint on a Unix socket: the first connect
closes nothing, a later one only the tab opened after the first look,
across a disconnect and a cleanup. It fails without the change (the
first connect closed the three tabs that were open).
@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants