Skip to content

fix: reuse existing blank tab in browser harness#478

Open
iiai-lab wants to merge 1 commit into
browser-use:mainfrom
iiai-lab:fix/reuse-existing-blank-tab
Open

fix: reuse existing blank tab in browser harness#478
iiai-lab wants to merge 1 commit into
browser-use:mainfrom
iiai-lab:fix/reuse-existing-blank-tab

Conversation

@iiai-lab

@iiai-lab iiai-lab commented Jun 30, 2026

Copy link
Copy Markdown

Summary

  • Reuse an existing blank/newtab page before creating a new target
  • Close a newly-created tab if new_tab(url) navigation fails
  • Update usage docs to prefer ensure_real_tab()+goto_url and add regressions

Test plan

  • py -3.13 -m pytest tests/unit/test_daemon.py tests/unit/test_helpers.py -q
  • py -3.13 -m pytest tests/unit -q

Summary by cubic

Reuse existing blank/new-tab pages to avoid tab spam. On navigation failure, close the new tab and restore the previous tab, or fall back to a safe tab. Docs now prefer ensure_real_tab() + goto_url(), with regression tests.

  • Bug Fixes
    • Daemon.attach_first_page now attaches to existing about:blank/about:newtab/chrome://newtab/ pages before creating one.
    • helpers.new_tab() reuses a current blank/new-tab when possible; on navigation failure it closes the created tab, restores the previous tab if available, otherwise switches to an existing tab or creates a fresh blank tab.

Written for commit 2a67bf5. Summary will update on new commits.

Review in cubic

@iiai-lab

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e3c0396afc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if url != "about:blank":
goto_url(url)
except Exception:
try: cdp("Target.closeTarget", targetId=tid)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore the previous session after cleanup

When goto_url() raises after switch_tab(tid) has already sent set_session, this cleanup closes the tab that the daemon is now attached to but leaves self.session/target_id pointing at the closed target. In callers that catch the navigation error and continue in the same harness invocation, the next command starts from a stale session or reattaches to whichever page attach_first_page() picks, instead of returning to the tab that was active before new_tab(). Capture the previous tab/session and switch back after closing the failed target.

Useful? React with 👍 / 👎.

@iiai-lab iiai-lab closed this Jun 30, 2026
@iiai-lab iiai-lab force-pushed the fix/reuse-existing-blank-tab branch from e3c0396 to 7594909 Compare June 30, 2026 02:55
@iiai-lab

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 7594909e79

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@iiai-lab iiai-lab reopened this Jun 30, 2026
@iiai-lab

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a888566bf6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


def is_reusable_empty_page(t):
"""True for visible empty tabs we can attach to instead of creating another one."""
return t["type"] == "page" and t.get("url", "") in {"about:blank", "about:newtab", "chrome://newtab/"}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reuse new-tab URLs in new_tab before creating a target

When Chrome reports the only empty tab as about:newtab or chrome://newtab/, this line now makes the daemon attach to that page during startup. The documented first navigation still goes through helpers.new_tab(url), but that helper only reuses "", about:blank, or about:blank#..., so it immediately creates another target instead of navigating the selected new-tab page. In fresh Chrome sessions this leaves the original new-tab page behind and reintroduces the tab spam this change is trying to avoid; either keep these URLs out of this reusable set or teach new_tab() to navigate them too.

Useful? React with 👍 / 👎.

@iiai-lab iiai-lab force-pushed the fix/reuse-existing-blank-tab branch from a888566 to 6583203 Compare June 30, 2026 03:09
@iiai-lab

Copy link
Copy Markdown
Author

@codex review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found and verified against the latest diff

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/browser_harness/daemon.py">

<violation number="1" location="src/browser_harness/daemon.py:191">
P2: New-tab reuse may miss common CDP new-tab URL variants because the allowlist only accepts `chrome://newtab/`.</violation>

<violation number="2" location="src/browser_harness/daemon.py:191">
P2: Inconsistent reusable-page criteria between `is_reusable_empty_page()` and `new_tab()`. This function treats `about:newtab` and `chrome://newtab/` as reusable (so the daemon attaches to them at startup), but `helpers.new_tab(url)` only reuses tabs with URL `""`, `"about:blank"`, or `"about:blank#..."`. In a fresh Chrome session where the sole tab is `about:newtab`, the daemon attaches to it, but the next `new_tab(url)` call won't navigate it—it will create another target, leaving the original newtab page behind. Either remove `about:newtab`/`chrome://newtab/` from this set or extend the reuse check in `new_tab()` to cover them as well.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread src/browser_harness/daemon.py

def is_reusable_empty_page(t):
"""True for visible empty tabs we can attach to instead of creating another one."""
return t["type"] == "page" and t.get("url", "") in {"about:blank", "about:newtab", "chrome://newtab/"}

@cubic-dev-ai cubic-dev-ai Bot Jun 30, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Inconsistent reusable-page criteria between is_reusable_empty_page() and new_tab(). This function treats about:newtab and chrome://newtab/ as reusable (so the daemon attaches to them at startup), but helpers.new_tab(url) only reuses tabs with URL "", "about:blank", or "about:blank#...". In a fresh Chrome session where the sole tab is about:newtab, the daemon attaches to it, but the next new_tab(url) call won't navigate it—it will create another target, leaving the original newtab page behind. Either remove about:newtab/chrome://newtab/ from this set or extend the reuse check in new_tab() to cover them as well.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/browser_harness/daemon.py, line 191:

<comment>Inconsistent reusable-page criteria between `is_reusable_empty_page()` and `new_tab()`. This function treats `about:newtab` and `chrome://newtab/` as reusable (so the daemon attaches to them at startup), but `helpers.new_tab(url)` only reuses tabs with URL `""`, `"about:blank"`, or `"about:blank#..."`. In a fresh Chrome session where the sole tab is `about:newtab`, the daemon attaches to it, but the next `new_tab(url)` call won't navigate it—it will create another target, leaving the original newtab page behind. Either remove `about:newtab`/`chrome://newtab/` from this set or extend the reuse check in `new_tab()` to cover them as well.</comment>

<file context>
@@ -186,6 +186,11 @@ def is_real_page(t):
 
+def is_reusable_empty_page(t):
+    """True for visible empty tabs we can attach to instead of creating another one."""
+    return t["type"] == "page" and t.get("url", "") in {"about:blank", "about:newtab", "chrome://newtab/"}
+
+
</file context>
Fix with cubic

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 6583203071

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@iiai-lab

Copy link
Copy Markdown
Author

@codex review

The latest head teaches helpers.new_tab() to reuse about:newtab/chrome://newtab/ as well, with a regression test. Please re-check the current head.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 6583203071

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 4 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/browser_harness/daemon.py">

<violation number="1" location="src/browser_harness/daemon.py:191">
P2: Inconsistent reusable-page criteria between `is_reusable_empty_page()` and `new_tab()`. This function treats `about:newtab` and `chrome://newtab/` as reusable (so the daemon attaches to them at startup), but `helpers.new_tab(url)` only reuses tabs with URL `""`, `"about:blank"`, or `"about:blank#..."`. In a fresh Chrome session where the sole tab is `about:newtab`, the daemon attaches to it, but the next `new_tab(url)` call won't navigate it—it will create another target, leaving the original newtab page behind. Either remove `about:newtab`/`chrome://newtab/` from this set or extend the reuse check in `new_tab()` to cover them as well.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread src/browser_harness/helpers.py
Prefer attaching to an existing empty tab before creating a new target, and close newly-created tabs if navigation fails. Update usage docs and add regression coverage.
@iiai-lab iiai-lab force-pushed the fix/reuse-existing-blank-tab branch from 6583203 to 2a67bf5 Compare June 30, 2026 03:20
@iiai-lab

Copy link
Copy Markdown
Author

@codex review

Updated current head also recovers to a fallback attached tab when previous current_tab cannot be captured. Please review current head.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 2a67bf5c2d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

1 participant