Skip to content

[Bug]: Dataclass Rect.__post_init__ silently ignores inverted bounds and calculate_paint_order permits non-positive dimensions #5987

Open

Description

@CodeItAlone

Browser Use Version

0.13.10

LLM Model

ChatBrowserUse / Gemini 3.8 flash

Screenshots, Description, and task prompt given to Agent

Description

In browser_use/dom/serializer/paint_order.py:

  1. Rect.__post_init__ return value is discarded:
    def __post_init__(self):
        if not (self.x1 <= self.x2 and self.y1 <= self.y2):
            return False

In Python @DataClass, post_init return values are ignored. If inverted coordinates (x1 > x2 or y1 > y2) are passed, the dataclass initializes silently with invalid negative bounds, corrupting occlusion calculations. It should raise ValueError.

Unhandled zero or negative dimensions in calculate_paint_order: Elements with bounds.width <= 0 or bounds.height <= 0 are passed into Rect(...) without filtering, causing non-visible or collapsed elements to enter occlusion calculations.

HTML around where it's failing

### 4. HTML around where it's failing *

<div style="width: 0px; height: 0px; overflow: hidden;">
  <span class="hidden-tracker"></span>
</div>

Operating System & Browser Versions

Windows 11 + Chromium v136 + browser-use v0.13.10 + Python 3.12

Python Code Sample

from browser_use.dom.serializer.paint_order import Rect

# Returns an instance silently instead of failing:
invalid_rect = Rect(x1=100.0, y1=50.0, x2=20.0, y2=10.0)
print(invalid_rect.area())  # Computes nonsensical area without error

Full DEBUG Log Output

DEBUG [browser_use.dom.serializer] Building paint order occlusion tree
DEBUG [browser_use.dom.serializer] Processed node bounds: Rect(x1=100.0, y1=50.0, x2=20.0, y2=10.0)
DEBUG [browser_use.dom.serializer] Invalid negative dimensions detected during occlusion pass

Activity

  1. added
    bug
    on Oct 3, 2026
  2. added a commit that references this issue on Oct 14, 2026
    05021a0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions