Bug: GIF overlay crashes with display_step=False (UnboundLocalError: y_step)

Author: feiiiiii5Created Sep 15, 2026Updated Sep 15, 2026

Browser Use Version

0.13.10 (origin/main @ 843819cb)

Bug Description, Steps to Reproduce, Screenshots

_add_overlay_to_image in browser_use/agent/gif.py accepts display_step: bool = True, but calling it with display_step=False crashes:

UnboundLocalError: cannot access local variable 'y_step' where it is not associated with a value

Root cause: y_step (line 358) and padding (line 361) are only assigned inside the if display_step: block, while the goal-text layout below uses both unconditionally (line 393: y_goal = y_step - goal_height - padding * 4). So the goal overlay -- which should render independently of the step badge -- can never be drawn without the step number.

The only in-repo caller (create_history_gif, line 215) leaves the default True, so this is latent there, but the parameter is part of the function's contract and any caller (or future generate_gif option) that disables the step badge hits the crash.

Failing Python Code

from PIL import Image, ImageFont
from browser_use.agent.gif import _add_overlay_to_image

img = Image.new('RGB', (800, 600), (10, 10, 10))
font = ImageFont.load_default()

# works
_add_overlay_to_image(img, 1, 'hello goal', font, font, 40, None, display_step=True)
# UnboundLocalError: cannot access local variable 'y_step' ...
_add_overlay_to_image(img, 1, 'hello goal', font, font, 40, None, display_step=False)

Expected behavior

With display_step=False the step badge is skipped and the goal text is drawn above the bottom margin (anchored the same way, with the step-badge height treated as 0).

LLM Model

n/a (no LLM involved, pure PIL path)