browser-use/browser-use · error · RuntimeError

No current target found

Error message

No current target found

What it means

must_get_current_page() is the strict variant of get_current_page(): it resolves the CDP target matching the current agent focus and raises RuntimeError('No current target found') when that resolution yields nothing. It fires when there is no focus target or the focus target no longer exists among known targets.

Source

Thrown at browser_use/browser/session.py:1365

		return Target(self, target_id)

	async def get_current_page(self) -> 'Page | None':
		"""Get the current page as an actor Page."""
		target_info = await self.get_current_target_info()

		if not target_info:
			return None

		from browser_use.actor.page import Page as Target

		return Target(self, target_info['targetId'])

	async def must_get_current_page(self) -> 'Page':
		"""Get the current page as an actor Page."""
		page = await self.get_current_page()
		if not page:
			raise RuntimeError('No current target found')

		return page

	async def get_pages(self) -> list['Page']:
		"""Get all available pages using SessionManager (source of truth)."""
		# Import here to avoid circular import
		from browser_use.actor.page import Page as PageActor

		page_targets = self.session_manager.get_all_page_targets() if self.session_manager else []

		targets = []
		for target in page_targets:
			targets.append(PageActor(self, target.target_id))

		return targets

	def get_focused_target(self) -> 'Target | None':
		"""Get the target that currently has agent focus.

View on GitHub (pinned to 6c73fced2f)

Solutions

  1. Use get_current_page() and handle None instead of must_get_current_page() when absence is expected
  2. Ensure at least one tab exists before acting: open about:blank if page_targets is empty
  3. After a tab closes, re-establish focus (switch_tab to most recent) before further page operations
  4. Verify browser.agent_focus_target_id is set and the browser is connected

Example fix

// before
page = await browser.must_get_current_page()  # raises when focus is gone

// after
page = await browser.get_current_page()
if page is None:
    # focus lost — recover by opening/switching to a tab
    await browser.switch_tab(None)  # most recent, or create new
    page = await browser.must_get_current_page()
Defensive patterns

Strategy: type-guard

Validate before calling

if await browser.get_current_page() is None:
    await browser.switch_tab(None)  # recover focus to most recent/new tab

Type guard

async def has_current_page(browser) -> bool:
    return await browser.get_current_page() is not None

Try / catch

try:
    page = await browser.must_get_current_page()
except RuntimeError as e:
    if 'No current target found' in str(e):
        page = None  # or recover focus then retry
    else:
        raise

Prevention

When it happens

Trigger: Calling must_get_current_page() (or APIs built on it) before start() finishes, after the focused tab was closed/crashed, or when the SessionManager has no page targets matching the current focus.

Common situations: Agent code taking screenshots or extracting DOM right after the last tab was closed by the page itself (window.close, target=_blank flows); session used after browser crash; race during startup.

Related errors


AI-assisted analysis of browser-use/browser-use@6c73fced2f (2026-08-14). Data as JSON: /api/errors/f08fb41e7cf25ac7. Report an issue: GitHub.