Skip to content

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

Include '' if attr none

Magnus Müllerff9c300b4968
diff --git a/browser_use/dom/serializer/serializer.py b/browser_use/dom/serializer/serializer.py
index b9d04bc12..c41747aee 100644
--- a/browser_use/dom/serializer/serializer.py
+++ b/browser_use/dom/serializer/serializer.py
@@ -1118,6 +1118,15 @@ class DOMTreeSerializer:
del attributes_to_include[attr]
if attributes_to_include:
- return ' '.join(f'{key}={cap_text_length(value, 100)}' for key, value in attributes_to_include.items())
+ # Format attributes, wrapping empty values in quotes for clarity
+ formatted_attrs = []
+ for key, value in attributes_to_include.items():
+ capped_value = cap_text_length(value, 100)
+ # Show empty values as key='' instead of key=
+ if not capped_value:
+ formatted_attrs.append(f"{key}=''")
+ else:
+ formatted_attrs.append(f'{key}={capped_value}')
+ return ' '.join(formatted_attrs)
return ''