Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

Revert

mertunsall3259c54ef6da
diff --git a/browser_use/tools/service.py b/browser_use/tools/service.py
index 066b3c023..c53493501 100644
--- a/browser_use/tools/service.py
+++ b/browser_use/tools/service.py
@@ -585,10 +585,10 @@ class Tools(Generic[Context]):
'Switch to another open tab by tab_id. Tab IDs are shown in browser state tabs list (last 4 chars of target_id). Use when you need to work with content in a different tab.',
param_model=SwitchTabAction,
)
- async def switch(tab_id: str, browser_session: BrowserSession):
+ async def switch(params: SwitchTabAction, browser_session: BrowserSession):
# Simple switch tab logic
try:
- target_id = await browser_session.get_target_id_from_tab_id(tab_id)
+ target_id = await browser_session.get_target_id_from_tab_id(params.tab_id)
event = browser_session.event_bus.dispatch(SwitchTabEvent(target_id=target_id))
await event
@@ -597,30 +597,30 @@ class Tools(Generic[Context]):
if new_target_id:
memory = f'Switched to tab #{new_target_id[-4:]}'
else:
- memory = f'Switched to tab #{tab_id}'
+ memory = f'Switched to tab #{params.tab_id}'
logger.info(f'🔄 {memory}')
return ActionResult(extracted_content=memory, long_term_memory=memory)
except Exception as e:
logger.warning(f'Tab switch may have failed: {e}')
- memory = f'Attempted to switch to tab #{tab_id}'
+ memory = f'Attempted to switch to tab #{params.tab_id}'
return ActionResult(extracted_content=memory, long_term_memory=memory)
@self.registry.action(
'Close a tab by tab_id. Tab IDs are shown in browser state tabs list (last 4 chars of target_id). Use to clean up tabs you no longer need.',
param_model=CloseTabAction,
)
- async def close(tab_id: str, browser_session: BrowserSession):
+ async def close(params: CloseTabAction, browser_session: BrowserSession):
# Simple close tab logic
try:
- target_id = await browser_session.get_target_id_from_tab_id(tab_id)
+ target_id = await browser_session.get_target_id_from_tab_id(params.tab_id)
# Dispatch close tab event - handle stale target IDs gracefully
event = browser_session.event_bus.dispatch(CloseTabEvent(target_id=target_id))
await event
await event.event_result(raise_if_any=False, raise_if_none=False) # Don't raise on errors
- memory = f'Closed tab #{tab_id}'
+ memory = f'Closed tab #{params.tab_id}'
logger.info(f'🗑️ {memory}')
return ActionResult(
extracted_content=memory,
@@ -628,8 +628,8 @@ class Tools(Generic[Context]):
)
except Exception as e:
# Handle stale target IDs gracefully
- logger.warning(f'Tab {tab_id} may already be closed: {e}')
- memory = f'Tab #{tab_id} closed (was already closed or invalid)'
+ logger.warning(f'Tab {params.tab_id} may already be closed: {e}')
+ memory = f'Tab #{params.tab_id} closed (was already closed or invalid)'
return ActionResult(
extracted_content=memory,
long_term_memory=memory,