Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: dispatch TabCreatedEvent for popups created by window.open()#4239

Open
OiPunk wants to merge 2 commits intobrowser-use:mainfrom
OiPunk:codex/browser-use-4208-popup-tab-event
Open

fix: dispatch TabCreatedEvent for popups created by window.open()#4239
OiPunk wants to merge 2 commits intobrowser-use:mainfrom
OiPunk:codex/browser-use-4208-popup-tab-event

Conversation

@OiPunk
Copy link

@OiPunk OiPunk commented Feb 28, 2026

Summary

Fixes #4208window.open() causes the previous page to freeze and new page stays on about:blank.

Root cause

When a popup is created via window.open(), Chrome attaches the new target through CDP Target.attachedToTarget. SessionManager._handle_target_attached() correctly enables page monitoring and creates a CDP session, but never dispatched TabCreatedEvent for externally-created targets.

Without TabCreatedEvent, none of the event-driven watchdogs initialize for the popup:

  • PopupsWatchdog never registers dialog handlers
  • AboutBlankWatchdog never processes the tab
  • SecurityWatchdog never checks the URL policy
  • BrowserSession.on_TabCreatedEvent never applies viewport settings

The result: popup stuck on about:blank, original page appears frozen.

Fix

Dispatch TabCreatedEvent from _handle_target_attached() for page/tab targets, right after _enable_page_monitoring(). This is the single place where all externally-created targets (popups, new tabs from links, window.open()) converge.

All existing on_TabCreatedEvent handlers are idempotent:

  • PopupsWatchdog — guards with _dialog_listeners_registered set
  • AboutBlankWatchdog — guards with __dvdAnimationRunning JS flag
  • CrashWatchdog — guards with _targets_with_listeners set
  • SecurityWatchdog / DownloadsWatchdog / DOMWatchdog — stateless checks

So the potential duplicate dispatch for internally-created tabs (which also emit TabCreatedEvent from the caller) is safe.

Changes

  • browser_use/browser/session_manager.py — 12-line addition in _handle_target_attached()
  • tests/ci/browser/test_popup_tab_created_event.py — 4 regression tests covering the event dispatch, URL navigation, watchdog initialization, and original page stability

Test plan

  • ruff check / ruff format --check pass
  • CI: pytest tests/ci/browser/test_popup_tab_created_event.py -v -s

AI-assisted testing, AI-assisted review


Summary by cubic

Fixes #4208 by dispatching TabCreatedEvent for window.open() popups so they initialize and don’t freeze on about:blank. Also defaults empty popup URLs to about:blank to satisfy SecurityWatchdog, keeping the opener page responsive.

  • Bug Fixes
    • Dispatch TabCreatedEvent in SessionManager._handle_target_attached() for page/tab targets after enabling page monitoring.
    • Set TabCreatedEvent.url to target_info.get('url') or 'about:blank' to handle empty-string URLs.
    • Simplified regression tests: event dispatch, URL validity, and opener page responsiveness.

Written for commit ae0a7a2. Summary will update on new commits.

…pen)

When a popup is created via window.open(), the browser attaches the new
target through CDP's Target.attachedToTarget. SessionManager handled the
attachment correctly (enabling page monitoring, creating CDP sessions) but
never dispatched TabCreatedEvent for these externally-created targets.

This meant all event-driven watchdogs — PopupsWatchdog, AboutBlankWatchdog,
SecurityWatchdog, etc. — never initialized for the popup tab. The practical
symptoms: dialog handlers missing, viewport settings not applied, and the
popup stuck on about:blank while the original page appeared frozen.

The fix dispatches TabCreatedEvent from _handle_target_attached() for page/
tab targets. All existing watchdog on_TabCreatedEvent handlers are already
idempotent, so the potential duplicate dispatch (for internally-created tabs
that also emit the event from the caller) is harmless.

Closes browser-use#4208
@CLAassistant
Copy link

CLAassistant commented Feb 28, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

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

Choose a reason for hiding this comment

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

No issues found across 2 files

The popup target's initial URL can be an empty string (not absent) when
Chrome attaches it.  Using `target_info.get('url', 'about:blank')` only
covers the absent-key case; `get('url') or 'about:blank'` handles both
absent and empty-string, preventing SecurityWatchdog from closing the
popup as "disallowed URL".

Also simplified the test suite:
- Replaced fragile tab-count assertion with event-based URL validation
- Removed internal-attribute test (PopupsWatchdog._dialog_listeners_registered)
- Kept core event dispatch test + URL validity test + original page test
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.

Bug: window.open() causes the previous page to freeze and prevents normal navigation to the new page

2 participants