optexity-browser-use 0.9.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- browser_use/__init__.py +157 -0
- browser_use/actor/__init__.py +11 -0
- browser_use/actor/element.py +1175 -0
- browser_use/actor/mouse.py +134 -0
- browser_use/actor/page.py +561 -0
- browser_use/actor/playground/flights.py +41 -0
- browser_use/actor/playground/mixed_automation.py +54 -0
- browser_use/actor/playground/playground.py +236 -0
- browser_use/actor/utils.py +176 -0
- browser_use/agent/cloud_events.py +282 -0
- browser_use/agent/gif.py +424 -0
- browser_use/agent/judge.py +170 -0
- browser_use/agent/message_manager/service.py +473 -0
- browser_use/agent/message_manager/utils.py +52 -0
- browser_use/agent/message_manager/views.py +98 -0
- browser_use/agent/prompts.py +413 -0
- browser_use/agent/service.py +2316 -0
- browser_use/agent/system_prompt.md +185 -0
- browser_use/agent/system_prompt_flash.md +10 -0
- browser_use/agent/system_prompt_no_thinking.md +183 -0
- browser_use/agent/views.py +743 -0
- browser_use/browser/__init__.py +41 -0
- browser_use/browser/cloud/cloud.py +203 -0
- browser_use/browser/cloud/views.py +89 -0
- browser_use/browser/events.py +578 -0
- browser_use/browser/profile.py +1158 -0
- browser_use/browser/python_highlights.py +548 -0
- browser_use/browser/session.py +3225 -0
- browser_use/browser/session_manager.py +399 -0
- browser_use/browser/video_recorder.py +162 -0
- browser_use/browser/views.py +200 -0
- browser_use/browser/watchdog_base.py +260 -0
- browser_use/browser/watchdogs/__init__.py +0 -0
- browser_use/browser/watchdogs/aboutblank_watchdog.py +253 -0
- browser_use/browser/watchdogs/crash_watchdog.py +335 -0
- browser_use/browser/watchdogs/default_action_watchdog.py +2729 -0
- browser_use/browser/watchdogs/dom_watchdog.py +817 -0
- browser_use/browser/watchdogs/downloads_watchdog.py +1277 -0
- browser_use/browser/watchdogs/local_browser_watchdog.py +461 -0
- browser_use/browser/watchdogs/permissions_watchdog.py +43 -0
- browser_use/browser/watchdogs/popups_watchdog.py +143 -0
- browser_use/browser/watchdogs/recording_watchdog.py +126 -0
- browser_use/browser/watchdogs/screenshot_watchdog.py +62 -0
- browser_use/browser/watchdogs/security_watchdog.py +280 -0
- browser_use/browser/watchdogs/storage_state_watchdog.py +335 -0
- browser_use/cli.py +2359 -0
- browser_use/code_use/__init__.py +16 -0
- browser_use/code_use/formatting.py +192 -0
- browser_use/code_use/namespace.py +665 -0
- browser_use/code_use/notebook_export.py +276 -0
- browser_use/code_use/service.py +1340 -0
- browser_use/code_use/system_prompt.md +574 -0
- browser_use/code_use/utils.py +150 -0
- browser_use/code_use/views.py +171 -0
- browser_use/config.py +505 -0
- browser_use/controller/__init__.py +3 -0
- browser_use/dom/enhanced_snapshot.py +161 -0
- browser_use/dom/markdown_extractor.py +169 -0
- browser_use/dom/playground/extraction.py +312 -0
- browser_use/dom/playground/multi_act.py +32 -0
- browser_use/dom/serializer/clickable_elements.py +200 -0
- browser_use/dom/serializer/code_use_serializer.py +287 -0
- browser_use/dom/serializer/eval_serializer.py +478 -0
- browser_use/dom/serializer/html_serializer.py +212 -0
- browser_use/dom/serializer/paint_order.py +197 -0
- browser_use/dom/serializer/serializer.py +1170 -0
- browser_use/dom/service.py +825 -0
- browser_use/dom/utils.py +129 -0
- browser_use/dom/views.py +906 -0
- browser_use/exceptions.py +5 -0
- browser_use/filesystem/__init__.py +0 -0
- browser_use/filesystem/file_system.py +619 -0
- browser_use/init_cmd.py +376 -0
- browser_use/integrations/gmail/__init__.py +24 -0
- browser_use/integrations/gmail/actions.py +115 -0
- browser_use/integrations/gmail/service.py +225 -0
- browser_use/llm/__init__.py +155 -0
- browser_use/llm/anthropic/chat.py +242 -0
- browser_use/llm/anthropic/serializer.py +312 -0
- browser_use/llm/aws/__init__.py +36 -0
- browser_use/llm/aws/chat_anthropic.py +242 -0
- browser_use/llm/aws/chat_bedrock.py +289 -0
- browser_use/llm/aws/serializer.py +257 -0
- browser_use/llm/azure/chat.py +91 -0
- browser_use/llm/base.py +57 -0
- browser_use/llm/browser_use/__init__.py +3 -0
- browser_use/llm/browser_use/chat.py +201 -0
- browser_use/llm/cerebras/chat.py +193 -0
- browser_use/llm/cerebras/serializer.py +109 -0
- browser_use/llm/deepseek/chat.py +212 -0
- browser_use/llm/deepseek/serializer.py +109 -0
- browser_use/llm/exceptions.py +29 -0
- browser_use/llm/google/__init__.py +3 -0
- browser_use/llm/google/chat.py +542 -0
- browser_use/llm/google/serializer.py +120 -0
- browser_use/llm/groq/chat.py +229 -0
- browser_use/llm/groq/parser.py +158 -0
- browser_use/llm/groq/serializer.py +159 -0
- browser_use/llm/messages.py +238 -0
- browser_use/llm/models.py +271 -0
- browser_use/llm/oci_raw/__init__.py +10 -0
- browser_use/llm/oci_raw/chat.py +443 -0
- browser_use/llm/oci_raw/serializer.py +229 -0
- browser_use/llm/ollama/chat.py +97 -0
- browser_use/llm/ollama/serializer.py +143 -0
- browser_use/llm/openai/chat.py +264 -0
- browser_use/llm/openai/like.py +15 -0
- browser_use/llm/openai/serializer.py +165 -0
- browser_use/llm/openrouter/chat.py +211 -0
- browser_use/llm/openrouter/serializer.py +26 -0
- browser_use/llm/schema.py +176 -0
- browser_use/llm/views.py +48 -0
- browser_use/logging_config.py +330 -0
- browser_use/mcp/__init__.py +18 -0
- browser_use/mcp/__main__.py +12 -0
- browser_use/mcp/client.py +544 -0
- browser_use/mcp/controller.py +264 -0
- browser_use/mcp/server.py +1114 -0
- browser_use/observability.py +204 -0
- browser_use/py.typed +0 -0
- browser_use/sandbox/__init__.py +41 -0
- browser_use/sandbox/sandbox.py +637 -0
- browser_use/sandbox/views.py +132 -0
- browser_use/screenshots/__init__.py +1 -0
- browser_use/screenshots/service.py +52 -0
- browser_use/sync/__init__.py +6 -0
- browser_use/sync/auth.py +357 -0
- browser_use/sync/service.py +161 -0
- browser_use/telemetry/__init__.py +51 -0
- browser_use/telemetry/service.py +112 -0
- browser_use/telemetry/views.py +101 -0
- browser_use/tokens/__init__.py +0 -0
- browser_use/tokens/custom_pricing.py +24 -0
- browser_use/tokens/mappings.py +4 -0
- browser_use/tokens/service.py +580 -0
- browser_use/tokens/views.py +108 -0
- browser_use/tools/registry/service.py +572 -0
- browser_use/tools/registry/views.py +174 -0
- browser_use/tools/service.py +1675 -0
- browser_use/tools/utils.py +82 -0
- browser_use/tools/views.py +100 -0
- browser_use/utils.py +670 -0
- optexity_browser_use-0.9.5.dist-info/METADATA +344 -0
- optexity_browser_use-0.9.5.dist-info/RECORD +147 -0
- optexity_browser_use-0.9.5.dist-info/WHEEL +4 -0
- optexity_browser_use-0.9.5.dist-info/entry_points.txt +3 -0
- optexity_browser_use-0.9.5.dist-info/licenses/LICENSE +21 -0
browser_use/dom/utils.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
def cap_text_length(text: str, max_length: int) -> str:
|
|
2
|
+
"""Cap text length for display."""
|
|
3
|
+
if len(text) <= max_length:
|
|
4
|
+
return text
|
|
5
|
+
return text[:max_length] + '...'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def generate_css_selector_for_element(enhanced_node) -> str | None:
|
|
9
|
+
"""Generate a CSS selector using node properties from version 0.5.0 approach."""
|
|
10
|
+
import re
|
|
11
|
+
|
|
12
|
+
if not enhanced_node or not hasattr(enhanced_node, 'tag_name') or not enhanced_node.tag_name:
|
|
13
|
+
return None
|
|
14
|
+
|
|
15
|
+
# Get base selector from tag name (simplified since we don't have xpath in EnhancedDOMTreeNode)
|
|
16
|
+
tag_name = enhanced_node.tag_name.lower().strip()
|
|
17
|
+
if not tag_name or not re.match(r'^[a-zA-Z][a-zA-Z0-9-]*$', tag_name):
|
|
18
|
+
return None
|
|
19
|
+
|
|
20
|
+
css_selector = tag_name
|
|
21
|
+
|
|
22
|
+
# Add ID if available (most specific)
|
|
23
|
+
if enhanced_node.attributes and 'id' in enhanced_node.attributes:
|
|
24
|
+
element_id = enhanced_node.attributes['id']
|
|
25
|
+
if element_id and element_id.strip():
|
|
26
|
+
element_id = element_id.strip()
|
|
27
|
+
# Validate ID contains only valid characters for # selector
|
|
28
|
+
if re.match(r'^[a-zA-Z][a-zA-Z0-9_-]*$', element_id):
|
|
29
|
+
return f'#{element_id}'
|
|
30
|
+
else:
|
|
31
|
+
# For IDs with special characters ($, ., :, etc.), use attribute selector
|
|
32
|
+
# Escape quotes in the ID value
|
|
33
|
+
escaped_id = element_id.replace('"', '\\"')
|
|
34
|
+
return f'{tag_name}[id="{escaped_id}"]'
|
|
35
|
+
|
|
36
|
+
# Handle class attributes (from version 0.5.0 approach)
|
|
37
|
+
if enhanced_node.attributes and 'class' in enhanced_node.attributes and enhanced_node.attributes['class']:
|
|
38
|
+
# Define a regex pattern for valid class names in CSS
|
|
39
|
+
valid_class_name_pattern = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_-]*$')
|
|
40
|
+
|
|
41
|
+
# Iterate through the class attribute values
|
|
42
|
+
classes = enhanced_node.attributes['class'].split()
|
|
43
|
+
for class_name in classes:
|
|
44
|
+
# Skip empty class names
|
|
45
|
+
if not class_name.strip():
|
|
46
|
+
continue
|
|
47
|
+
|
|
48
|
+
# Check if the class name is valid
|
|
49
|
+
if valid_class_name_pattern.match(class_name):
|
|
50
|
+
# Append the valid class name to the CSS selector
|
|
51
|
+
css_selector += f'.{class_name}'
|
|
52
|
+
|
|
53
|
+
# Expanded set of safe attributes that are stable and useful for selection (from v0.5.0)
|
|
54
|
+
SAFE_ATTRIBUTES = {
|
|
55
|
+
# Data attributes (if they're stable in your application)
|
|
56
|
+
'id',
|
|
57
|
+
# Standard HTML attributes
|
|
58
|
+
'name',
|
|
59
|
+
'type',
|
|
60
|
+
'placeholder',
|
|
61
|
+
# Accessibility attributes
|
|
62
|
+
'aria-label',
|
|
63
|
+
'aria-labelledby',
|
|
64
|
+
'aria-describedby',
|
|
65
|
+
'role',
|
|
66
|
+
# Common form attributes
|
|
67
|
+
'for',
|
|
68
|
+
'autocomplete',
|
|
69
|
+
'required',
|
|
70
|
+
'readonly',
|
|
71
|
+
# Media attributes
|
|
72
|
+
'alt',
|
|
73
|
+
'title',
|
|
74
|
+
'src',
|
|
75
|
+
# Custom stable attributes (add any application-specific ones)
|
|
76
|
+
'href',
|
|
77
|
+
'target',
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
# Always include dynamic attributes (include_dynamic_attributes=True equivalent)
|
|
81
|
+
include_dynamic_attributes = True
|
|
82
|
+
if include_dynamic_attributes:
|
|
83
|
+
dynamic_attributes = {
|
|
84
|
+
'data-id',
|
|
85
|
+
'data-qa',
|
|
86
|
+
'data-cy',
|
|
87
|
+
'data-testid',
|
|
88
|
+
}
|
|
89
|
+
SAFE_ATTRIBUTES.update(dynamic_attributes)
|
|
90
|
+
|
|
91
|
+
# Handle other attributes (from version 0.5.0 approach)
|
|
92
|
+
if enhanced_node.attributes:
|
|
93
|
+
for attribute, value in enhanced_node.attributes.items():
|
|
94
|
+
if attribute == 'class':
|
|
95
|
+
continue
|
|
96
|
+
|
|
97
|
+
# Skip invalid attribute names
|
|
98
|
+
if not attribute.strip():
|
|
99
|
+
continue
|
|
100
|
+
|
|
101
|
+
if attribute not in SAFE_ATTRIBUTES:
|
|
102
|
+
continue
|
|
103
|
+
|
|
104
|
+
# Escape special characters in attribute names
|
|
105
|
+
safe_attribute = attribute.replace(':', r'\:')
|
|
106
|
+
|
|
107
|
+
# Handle different value cases
|
|
108
|
+
if value == '':
|
|
109
|
+
css_selector += f'[{safe_attribute}]'
|
|
110
|
+
elif any(char in value for char in '"\'<>`\n\r\t'):
|
|
111
|
+
# Use contains for values with special characters
|
|
112
|
+
# For newline-containing text, only use the part before the newline
|
|
113
|
+
if '\n' in value:
|
|
114
|
+
value = value.split('\n')[0]
|
|
115
|
+
# Regex-substitute *any* whitespace with a single space, then strip.
|
|
116
|
+
collapsed_value = re.sub(r'\s+', ' ', value).strip()
|
|
117
|
+
# Escape embedded double-quotes.
|
|
118
|
+
safe_value = collapsed_value.replace('"', '\\"')
|
|
119
|
+
css_selector += f'[{safe_attribute}*="{safe_value}"]'
|
|
120
|
+
else:
|
|
121
|
+
css_selector += f'[{safe_attribute}="{value}"]'
|
|
122
|
+
|
|
123
|
+
# Final validation: ensure the selector is safe and doesn't contain problematic characters
|
|
124
|
+
# Note: quotes are allowed in attribute selectors like [name="value"]
|
|
125
|
+
if css_selector and not any(char in css_selector for char in ['\n', '\r', '\t']):
|
|
126
|
+
return css_selector
|
|
127
|
+
|
|
128
|
+
# If we get here, the selector was problematic, return just the tag name as fallback
|
|
129
|
+
return tag_name
|