Skip to content

Commit 8d396c9

Browse files
authored
Merge pull request #555 from browser-use/upgrade-to-0-1-42
Upgrade to browser-use pip 0.1.42
2 parents 664f874 + 40a61fa commit 8d396c9

File tree

10 files changed

+816
-481
lines changed

10 files changed

+816
-481
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,6 @@ data/
187187

188188
# For Config Files (Current Settings)
189189
.config.pkl
190-
*.pdf
190+
*.pdf
191+
192+
workflow

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,7 @@ uv pip install -r requirements.txt
6868
Install Browsers in Playwright:
6969
You can install specific browsers by running:
7070
```bash
71-
playwright install --with-deps chromium
72-
```
73-
74-
To install all browsers:
75-
```bash
76-
playwright install
71+
patchright install chromium
7772
```
7873

7974
#### Step 4: Configure Environment

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
browser-use==0.1.41
1+
browser-use==0.1.42
22
pyperclip==1.9.0
33
gradio==5.27.0
44
json-repair
Lines changed: 30 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,37 @@
11
from __future__ import annotations
22

33
import asyncio
4-
import gc
5-
import inspect
6-
import json
74
import logging
85
import os
9-
import re
10-
import time
11-
from pathlib import Path
12-
from typing import Any, Awaitable, Callable, Dict, Generic, List, Optional, TypeVar, Union
13-
14-
from dotenv import load_dotenv
15-
from langchain_core.language_models.chat_models import BaseChatModel
16-
from langchain_core.messages import (
17-
BaseMessage,
18-
HumanMessage,
19-
SystemMessage,
20-
)
216

227
# from lmnr.sdk.decorators import observe
23-
from pydantic import BaseModel, ValidationError
24-
258
from browser_use.agent.gif import create_history_gif
26-
from browser_use.agent.memory.service import Memory, MemorySettings
27-
from browser_use.agent.message_manager.service import MessageManager, MessageManagerSettings
28-
from browser_use.agent.message_manager.utils import convert_input_messages, extract_json_from_model_output, save_conversation
29-
from browser_use.agent.prompts import AgentMessagePrompt, PlannerPrompt, SystemPrompt
9+
from browser_use.agent.service import Agent, AgentHookFunc
3010
from browser_use.agent.views import (
31-
REQUIRED_LLM_API_ENV_VARS,
32-
ActionResult,
33-
AgentError,
34-
AgentHistory,
35-
AgentHistoryList,
36-
AgentOutput,
37-
AgentSettings,
38-
AgentState,
39-
AgentStepInfo,
40-
StepMetadata,
41-
ToolCallingMethod,
42-
)
43-
from browser_use.browser.browser import Browser
44-
from browser_use.browser.context import BrowserContext
45-
from browser_use.browser.views import BrowserState, BrowserStateHistory
46-
from browser_use.controller.registry.views import ActionModel
47-
from browser_use.controller.service import Controller
48-
from browser_use.dom.history_tree_processor.service import (
49-
DOMHistoryElement,
50-
HistoryTreeProcessor,
11+
AgentHistoryList,
12+
AgentStepInfo,
5113
)
52-
from browser_use.exceptions import LLMException
53-
from browser_use.telemetry.service import ProductTelemetry
5414
from browser_use.telemetry.views import (
55-
AgentEndTelemetryEvent,
56-
AgentRunTelemetryEvent,
57-
AgentStepTelemetryEvent,
15+
AgentEndTelemetryEvent,
5816
)
59-
from browser_use.utils import check_env_variables, time_execution_async, time_execution_sync
60-
from browser_use.agent.service import Agent, AgentHookFunc
17+
from browser_use.utils import time_execution_async
18+
from dotenv import load_dotenv
6119

6220
load_dotenv()
6321
logger = logging.getLogger(__name__)
6422

65-
SKIP_LLM_API_KEY_VERIFICATION = os.environ.get('SKIP_LLM_API_KEY_VERIFICATION', 'false').lower()[0] in 'ty1'
23+
SKIP_LLM_API_KEY_VERIFICATION = (
24+
os.environ.get("SKIP_LLM_API_KEY_VERIFICATION", "false").lower()[0] in "ty1"
25+
)
6626

6727

6828
class BrowserUseAgent(Agent):
69-
@time_execution_async('--run (agent)')
29+
@time_execution_async("--run (agent)")
7030
async def run(
71-
self, max_steps: int = 100, on_step_start: AgentHookFunc | None = None,
72-
on_step_end: AgentHookFunc | None = None
31+
self,
32+
max_steps: int = 100,
33+
on_step_start: AgentHookFunc | None = None,
34+
on_step_end: AgentHookFunc | None = None,
7335
) -> AgentHistoryList:
7436
"""Execute the task with maximum number of steps"""
7537

@@ -88,7 +50,7 @@ async def run(
8850
signal_handler.register()
8951

9052
# Wait for verification task to complete if it exists
91-
if hasattr(self, '_verification_task') and not self._verification_task.done():
53+
if hasattr(self, "_verification_task") and not self._verification_task.done():
9254
try:
9355
await self._verification_task
9456
except Exception:
@@ -100,7 +62,9 @@ async def run(
10062

10163
# Execute initial actions if provided
10264
if self.initial_actions:
103-
result = await self.multi_act(self.initial_actions, check_for_new_elements=False)
65+
result = await self.multi_act(
66+
self.initial_actions, check_for_new_elements=False
67+
)
10468
self.state.last_result = result
10569

10670
for step in range(max_steps):
@@ -112,12 +76,14 @@ async def run(
11276

11377
# Check if we should stop due to too many failures
11478
if self.state.consecutive_failures >= self.settings.max_failures:
115-
logger.error(f'❌ Stopping due to {self.settings.max_failures} consecutive failures')
79+
logger.error(
80+
f"❌ Stopping due to {self.settings.max_failures} consecutive failures"
81+
)
11682
break
11783

11884
# Check control flags before each step
11985
if self.state.stopped:
120-
logger.info('Agent stopped')
86+
logger.info("Agent stopped")
12187
break
12288

12389
while self.state.paused:
@@ -142,13 +108,15 @@ async def run(
142108
await self.log_completion()
143109
break
144110
else:
145-
logger.info('❌ Failed to complete task in maximum steps')
111+
logger.info("❌ Failed to complete task in maximum steps")
146112

147113
return self.state.history
148114

149115
except KeyboardInterrupt:
150116
# Already handled by our signal handler, but catch any direct KeyboardInterrupt as well
151-
logger.info('Got KeyboardInterrupt during execution, returning current history')
117+
logger.info(
118+
"Got KeyboardInterrupt during execution, returning current history"
119+
)
152120
return self.state.history
153121

154122
finally:
@@ -171,8 +139,10 @@ async def run(
171139
await self.close()
172140

173141
if self.settings.generate_gif:
174-
output_path: str = 'agent_history.gif'
142+
output_path: str = "agent_history.gif"
175143
if isinstance(self.settings.generate_gif, str):
176144
output_path = self.settings.generate_gif
177145

178-
create_history_gif(task=self.task, history=self.state.history, output_path=output_path)
146+
create_history_gif(
147+
task=self.task, history=self.state.history, output_path=output_path
148+
)

0 commit comments

Comments
 (0)