Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
tiny speedup
Gregor Žuničf53ecd543bad
diff --git a/src/dom/service.py b/src/dom/service.pyindex a62ac8a0f..61da3b376 100644--- a/src/dom/service.py+++ b/src/dom/service.py@@ -36,6 +36,12 @@ class DomService:element = dom_queue.pop()should_add_element = False+ # Add quick filter before expensive checks+ if not self._quick_element_filter(element):+ if isinstance(element, Tag):+ element.decompose()+ continue+# Handle both Tag elements and text nodesif isinstance(element, Tag):if not self._is_element_accepted(element):@@ -431,3 +437,40 @@ class DomService:or element.get('hidden') is not Noneor element.get('aria-disabled') == 'true')++ def _quick_element_filter(self, element: PageElement) -> bool:+ """+ Quick pre-filter to eliminate elements before expensive checks.+ Returns True if element passes initial filtering.+ """+ if isinstance(element, NavigableString):+ # Quick check for empty or whitespace-only strings+ return bool(element.strip())++ if not isinstance(element, Tag):+ return False++ style = element.get('style')++ # Quick attribute checks that would make element invisible/non-interactive+ if any(+ [+ element.get('aria-hidden') == 'true',+ element.get('hidden') is not None,+ element.get('disabled') is not None,+ style and ('display: none' in style or 'visibility: hidden' in style),+ element.has_attr('class')+ and any(cls in element['class'] for cls in ['hidden', 'invisible']),+ # Common hidden class patterns+ element.get('type') == 'hidden',+ ]+ ):+ return False++ # Skip elements that definitely won't be interactive or visible+ non_interactive_display = ['none', 'hidden']+ computed_style = element.get('style', '') or ''+ if any(display in computed_style for display in non_interactive_display):+ return False++ return Truediff --git a/src/dom/tests/extraction_test.py b/src/dom/tests/extraction_test.pyindex 2d2888fc6..eb1fe95c3 100644--- a/src/dom/tests/extraction_test.py+++ b/src/dom/tests/extraction_test.py@@ -40,7 +40,7 @@ def test_process_html_file():print(f'get_clickable_elements took {elapsed_time:.2f} seconds')- print(elements)+ # print(elements)# for item in result.items:# print(item)@@ -60,4 +60,4 @@ def test_process_html_file():# print('Tokens:', count_string_tokens(result.output_html, 'gpt-4o'))- input('Press enter to exit')+ # input('Press enter to exit')