Skip to content

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

fix: remove unused variable assignments

Saurav Panda2895720eb07e
diff --git a/browser_use/agent/gif.py b/browser_use/agent/gif.py
index 6bbf0b86f..eaf5b091c 100644
--- a/browser_use/agent/gif.py
+++ b/browser_use/agent/gif.py
@@ -108,7 +108,6 @@ def create_history_gif(
font_name = os.path.join(CONFIG.WIN_FONT_DIR, font_name + '.ttf')
regular_font = ImageFont.truetype(font_name, font_size)
title_font = ImageFont.truetype(font_name, title_font_size)
- goal_font = ImageFont.truetype(font_name, goal_font_size)
font_loaded = True
break
except OSError:
@@ -121,8 +120,6 @@ def create_history_gif(
regular_font = ImageFont.load_default()
title_font = ImageFont.load_default()
- goal_font = regular_font
-
# Load logo if requested
logo = None
if show_logo:
@@ -236,8 +233,6 @@ def _create_task_frame(
# Start with base font size (regular + 16)
base_font_size = regular_font.size + 16
min_font_size = max(regular_font.size - 10, 16) # Don't go below 16pt
- max_font_size = base_font_size # Cap at the base font size
-
# Calculate dynamic font size based on text length and complexity
# Longer texts get progressively smaller fonts
text_length = len(task)
diff --git a/browser_use/agent/message_manager/service.py b/browser_use/agent/message_manager/service.py
index 1e3261575..a83044ff2 100644
--- a/browser_use/agent/message_manager/service.py
+++ b/browser_use/agent/message_manager/service.py
@@ -300,7 +300,6 @@ class MessageManager:
self.state.read_state_images = [] # Clear images from previous step
action_results = ''
- result_len = len(result)
read_state_idx = 0
for idx, action_result in enumerate(result):
diff --git a/browser_use/agent/prompts.py b/browser_use/agent/prompts.py
index 7ce050ac5..4a06a994f 100644
--- a/browser_use/agent/prompts.py
+++ b/browser_use/agent/prompts.py
@@ -252,14 +252,11 @@ class AgentMessagePrompt:
pages_below = pi.pixels_below / pi.viewport_height if pi.viewport_height > 0 else 0
has_content_above = pages_above > 0
has_content_below = pages_below > 0
- total_pages = pi.page_height / pi.viewport_height if pi.viewport_height > 0 else 0
- current_page_position = pi.scroll_y / max(pi.page_height - pi.viewport_height, 1)
page_info_text = '<page_info>'
page_info_text += f'{pages_above:.1f} above, '
page_info_text += f'{pages_below:.1f} below '
page_info_text += '</page_info>\n'
- # , at {current_page_position:.0%} of page
if elements_text != '':
if not has_content_above:
elements_text = f'[Start of page]\n{elements_text}'
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index 4815e0a03..08e61d51e 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -2044,8 +2044,6 @@ class Agent(Generic[Context, AgentStructuredOutput]):
if not (self.logger.isEnabledFor(logging.DEBUG) and parsed.action):
return
- action_count = len(parsed.action)
-
# Collect action details
action_details = []
for i, action in enumerate(parsed.action):
@@ -2687,7 +2685,6 @@ class Agent(Generic[Context, AgentStructuredOutput]):
to pre-action values. Any change aborts the remaining queue.
"""
results: list[ActionResult] = []
- time_elapsed = 0
total_actions = len(actions)
assert self.browser_session is not None, 'BrowserSession is not set up'
@@ -2697,14 +2694,11 @@ class Agent(Generic[Context, AgentStructuredOutput]):
and self.browser_session._cached_browser_state_summary.dom_state is not None
):
cached_selector_map = dict(self.browser_session._cached_browser_state_summary.dom_state.selector_map)
- cached_element_hashes = {e.parent_branch_hash() for e in cached_selector_map.values()}
else:
cached_selector_map = {}
- cached_element_hashes = set()
except Exception as e:
self.logger.error(f'Error getting cached selector map: {e}')
cached_selector_map = {}
- cached_element_hashes = set()
for i, action in enumerate(actions):
# Get action name from the action model BEFORE try block to ensure it's always available in except
@@ -2733,8 +2727,6 @@ class Agent(Generic[Context, AgentStructuredOutput]):
pre_action_url = await self.browser_session.get_current_page_url()
pre_action_focus = self.browser_session.agent_focus_target_id
- time_start = time.time()
-
result = await self.tools.act(
action=action,
browser_session=self.browser_session,
@@ -2745,9 +2737,6 @@ class Agent(Generic[Context, AgentStructuredOutput]):
extraction_schema=self.extraction_schema,
)
- time_end = time.time()
- time_elapsed = time_end - time_start
-
if result.error:
await self._demo_mode_log(
f'Action "{action_name}" failed: {result.error}',
@@ -3445,7 +3434,6 @@ class Agent(Generic[Context, AgentStructuredOutput]):
hist_node = historical_elem.node_name.lower() if historical_elem else ''
similar_elements = []
if historical_elem and historical_elem.attributes:
- hist_aria = historical_elem.attributes.get('aria-label', '')
for idx, elem in selector_map.items():
if elem.node_name.lower() == hist_node and elem.attributes:
elem_aria = elem.attributes.get('aria-label', '')
diff --git a/browser_use/tokens/service.py b/browser_use/tokens/service.py
index ad5508f2c..edc735b86 100644
--- a/browser_use/tokens/service.py
+++ b/browser_use/tokens/service.py
@@ -250,9 +250,7 @@ class TokenCost:
# ANSI color codes
C_CYAN = '\033[96m'
- C_YELLOW = '\033[93m'
C_GREEN = '\033[92m'
- C_BLUE = '\033[94m'
C_RESET = '\033[0m'
# Always get cost breakdown for token details (even if not showing costs)
@@ -402,7 +400,6 @@ class TokenCost:
total_completion = sum(u.usage.completion_tokens for u in filtered_usage)
total_tokens = total_prompt + total_completion
total_prompt_cached = sum(u.usage.prompt_cached_tokens or 0 for u in filtered_usage)
- models = list({u.model for u in filtered_usage})
# Calculate per-model stats with record-by-record cost calculation
model_stats: dict[str, ModelUsageStats] = {}