Skip to content

fix(dom): reject inverted rects and skip collapsed nodes in paint order - #6275

Open
HhH666-ux wants to merge 2 commits into
browser-use:0.xfrom
HhH666-ux:fix/paint-order-rect-validation
Open

HhH666-ux wants to merge 2 commits into
browser-use:0.xfrom
HhH666-ux:fix/paint-order-rect-validation

Conversation

@HhH666-ux

@HhH666-ux HhH666-ux commented Oct 31, 2026 •

Copy link
Copy Markdown

Summary

Rect.__post_init__ validated the corner order with return False, which dataclasses ignore: Rect(x1=100, y1=50, x2=20, y2=10) was constructed silently with a negative area and then entered occlusion calculations.

PaintOrderRemover.calculate_paint_order() also built rects from any non-empty bounds, including collapsed elements with width <= 0 or height <= 0, so zero-area rects could take part in the union and flag other nodes as occluded.

This makes Rect raise ValueError for inverted bounds and skips non-positive bounds before the rect is created.

Tests

tests/ci/test_paint_order_rect_validation.py covers:

  • inverted bounds raise ValueError (horizontal and vertical inversion)
  • a valid rect keeps its area
  • two zero-width nodes no longer mark each other ignored_by_paint_order

The validation tests fail on unmodified main (DID NOT RAISE ValueError), and the existing tests/ci/test_dom_paint_order_serialization.py still passes with the change.

Fixes #5987


Summary by cubic

Fixes #5987: inverted rectangle bounds silently corrupted occlusion math, and collapsed elements could mark other nodes as occluded.

Rect.__post_init__ returned False, which dataclasses ignore, so inverted bounds produced negative-area rects that entered paint-order calculations. It now raises ValueError. collect_paint_order also builds rects from collapsed elements (width or height ≤ 0) and let their zero-area rects join the union, so two collapsed siblings at the same point could flag each other as occluded. Collapsed rects now stay out of the union, but the check runs after occlusion detection so a collapsed node covered by a real element is still marked ignored_by_paint_order.

Written for commit 14d4e82. Summary will update on new commits.

View guided diff

@mintlify

mintlify Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 14d4e82.

Approve preview

@CLAassistant

CLAassistant commented Oct 31, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Heads up: you’re close to your flex budget. Increase your flex budget so reviews don’t pause.

View guided diff | Re-trigger cubic

…occlusion flag

The collapsed-bounds guard ran before the `contains` check, so a zero-area node covered by a real
element stopped being marked `ignored_by_paint_order`. Its rect only has to stay out of the union;
occlusion detection still applies to it.

Adds the x-only / y-only inversion cases and a zero-height collapsed case, plus a regression test
for the covered-collapsed-node path.
@HhH666-ux
HhH666-ux changed the base branch from main to 0.x November 17, 2026 01:50
@HhH666-ux

Copy link
Copy Markdown
Author

Retargeted this to 0.x: main is 1.0, where browser_use/dom/serializer/paint_order.py no longer exists — the agent writes Python cells against raw CDP instead of walking a serialized DOM, so there is no paint-order pass on main for this to fix.

No code changed: the branch was cut from the 0.x tip (b49a68e), so the diff and the regression test are the ones already reviewed, and the test job (test_paint_order_rect_validation) is green.

The bug, briefly: the paint-order walk accepted any rect as a paint candidate, including inverted ones (right < left or bottom < top) and zero-area rects from collapsed nodes, so those nodes could claim a stacking position and shadow the element that actually paints on top. The fix rejects inverted and empty rects before they enter the ordering.

Happy to close it if 0.x is no longer taking fixes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants