Skip to content

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

Fix send_keys for words in natural langugae

Magnus Müller7a88f1afd2fd
diff --git a/browser_use/controller/service.py b/browser_use/controller/service.py
index bc5a220ee..e99d76960 100644
--- a/browser_use/controller/service.py
+++ b/browser_use/controller/service.py
@@ -227,7 +227,19 @@ class Controller:
async def send_keys(params: SendKeysAction, browser: BrowserContext):
page = await browser.get_current_page()
- await page.keyboard.press(params.keys)
+ try:
+ await page.keyboard.press(params.keys)
+ except Exception as e:
+ if 'Unknown key' in str(e):
+ # loop over the keys and try to send each one
+ for key in params.keys:
+ try:
+ await page.keyboard.press(key)
+ except Exception as e:
+ logger.debug(f'Error sending key {key}: {str(e)}')
+ raise e
+ else:
+ raise e
msg = f'⌨️ Sent keys: {params.keys}'
logger.info(msg)
return ActionResult(extracted_content=msg, include_in_memory=True)