Skip to content

feat(dom): add debug logging for element exclusion in DOM serializer#4601

Open
SaishMendke wants to merge 1 commit intobrowser-use:mainfrom
SaishMendke:fix/dom-element-exclusion-logs
Open

feat(dom): add debug logging for element exclusion in DOM serializer#4601
SaishMendke wants to merge 1 commit intobrowser-use:mainfrom
SaishMendke:fix/dom-element-exclusion-logs

Conversation

@SaishMendke
Copy link
Copy Markdown

@SaishMendke SaishMendke commented Apr 3, 2026

Summary

Adds structured debug logs explaining why elements are excluded from the selector_map during DOM serialization. This helps users diagnose why certain page elements aren't detected by the agent.

Covers three exclusion scenarios:

  • BBox containment filtering — element contained within a propagating parent (e.g., <svg> inside <a>)
  • Paint order occlusion — element fully covered by higher z-index elements
  • Interactive element not added — interactive element skipped due to bbox/paint-order exclusion

Closes #3913

Changes

  • browser_use/dom/serializer/serializer.py:

    • Added module-level logger (replacing inline import logging calls)
    • Refactored existing inline diagnostic logging into _log_interactive_no_snapshot() method
    • Added _log_element_excluded_by_bbox() and _log_interactive_element_not_added() methods
    • All logging methods follow the repo's _log_ prefix convention per CLAUDE.md
  • browser_use/dom/serializer/paint_order.py:

    • Added module-level logger
    • Added _log_element_excluded_by_paint_order() static method

Design decisions

  • _log_ methods — per CLAUDE.md convention to keep logging logic out of main code paths
  • logger.isEnabledFor(logging.DEBUG) guard — avoids expensive f-string formatting in hot loops when debug logging is off
  • Null-safe — explicit checks for snapshot_node and bounds before accessing, so pyright passes with 0 errors
  • No emoji in new log messages — kept consistent with the majority of debug logs in the codebase

Test plan

  • uv run ruff check — all checks passed
  • uv run ruff format --check — already formatted
  • uv run pyright on changed files — 0 errors, 0 warnings
  • uv run pytest -vxs tests/ci/772 passed, 29 skipped, 0 failures
  • Specifically verified DOM-adjacent tests: test_ax_name_matching, test_screenshot_exclusion, test_search_find, test_history_wait_time — all pass

Summary by cubic

Adds structured debug logs that explain why elements are excluded from the selector_map during DOM serialization. Helps diagnose why some elements aren’t detected.

  • New Features
    • Logs when nodes are excluded: bounding-box containment, paint-order occlusion, and interactive elements skipped due to these filters.
    • Centralized _log_* helpers and module-level logger with DEBUG guards and null-safe checks to avoid overhead and errors.

Written for commit bb8fcfe. Summary will update on new commits.

Add structured debug logs explaining why elements are excluded from the
selector map during DOM serialization. Covers three exclusion scenarios:
bbox containment filtering, paint order occlusion, and interactive
element skip reasons.

Closes browser-use#3913
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Saish Mendke seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

No issues found across 2 files

@gitguardian
Copy link
Copy Markdown

gitguardian Bot commented Apr 21, 2026

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

Since your pull request originates from a forked repository, GitGuardian is not able to associate the secrets uncovered with secret incidents on your GitGuardian dashboard.
Skipping this check run and merging your pull request will create secret incidents on your GitGuardian dashboard.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
- - Generic High Entropy Secret 3f9520c examples/glazyr_benchmark.py View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

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.

Feature Request: add log for removing dom element

2 participants