Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

removed unnecesary code

Gregor Žuničf33beaf800d0
diff --git a/browser_use/dom/buildDomTree.js b/browser_use/dom/buildDomTree.js
index f26dcc73a..a616bf532 100644
--- a/browser_use/dom/buildDomTree.js
+++ b/browser_use/dom/buildDomTree.js
@@ -523,6 +523,10 @@
/**
* Checks if an element is interactive.
+ *
+ * lots of comments, and uncommented code - to show the logic of what we already tried
+ *
+ * One of the things we tried at the beggining was also to use event listeners, and other fancy class, style stuff -> what actually worked best was just combining most things with computed cursor style :)
*/
function isInteractiveElement(element) {
if (!element || element.nodeType !== Node.ELEMENT_NODE) {
@@ -657,21 +661,9 @@
return true;
}
- // return false
-
-
-
const tagName = element.tagName.toLowerCase();
const role = element.getAttribute("role");
const ariaRole = element.getAttribute("aria-role");
- const tabIndex = element.getAttribute("tabindex");
-
- // Add check for specific class
- // const hasAddressInputClass = element.classList && (
- // element.classList.contains("address-input__container__input") ||
- // element.classList.contains("nav-btn") ||
- // element.classList.contains("pull-left")
- // );
// Added enhancement to capture dropdown interactive elements
if (element.classList && (
@@ -684,8 +676,6 @@
return true;
}
- // return false
-
const interactiveRoles = new Set([
'button', // Directly clickable element
// 'link', // Clickable link
@@ -715,72 +705,6 @@
if (hasInteractiveRole) return true;
return false
-
-
-
- // Check for event listeners
- const hasClickHandler =
- element.onclick !== null ||
- element.getAttribute("onclick") !== null ||
- element.hasAttribute("ng-click") ||
- element.hasAttribute("@click") ||
- element.hasAttribute("v-on:click");
-
- // Helper function to safely get event listeners
- function getEventListeners(el) {
- try {
- return window.getEventListeners?.(el) || {};
- } catch (e) {
- const listeners = {};
- const eventTypes = [
- "click",
- ];
-
- for (const type of eventTypes) {
- const handler = el[`on${type}`];
- if (handler) {
- listeners[type] = [{ listener: handler, useCapture: false }];
- }
- }
- return listeners;
- }
- }
-
- // Check for click-related events
- const listeners = getEventListeners(element);
- const hasClickListeners =
- listeners &&
- (listeners.click?.length > 0 ||
- listeners.mousedown?.length > 0 ||
- listeners.mouseup?.length > 0 ||
- listeners.touchstart?.length > 0 ||
- listeners.touchend?.length > 0);
-
- // Check for ARIA properties
- const hasAriaProps =
- element.hasAttribute("aria-expanded") ||
- element.hasAttribute("aria-pressed") ||
- element.hasAttribute("aria-selected") ||
- element.hasAttribute("aria-checked");
-
- const isContentEditable = element.getAttribute("contenteditable") === "true" ||
- element.isContentEditable ||
- element.id === "tinymce" ||
- element.classList.contains("mce-content-body") ||
- (element.tagName.toLowerCase() === "body" && element.getAttribute("data-id")?.startsWith("mce_"));
-
- // Check if element is draggable
- const isDraggable =
- element.draggable || element.getAttribute("draggable") === "true";
-
- return (
- // hasAriaProps ||
- // hasClickHandler ||
- // hasClickListeners ||
- // isDraggable ||
- // isContentEditable ||
- false
- );
}
@@ -868,6 +792,8 @@
* Checks if an element is within the expanded viewport.
*/
function isInExpandedViewport(element, viewportExpansion) {
+ return true
+
if (viewportExpansion === -1) {
return true;
}
diff --git a/browser_use/dom/tests/extraction_test.py b/browser_use/dom/tests/extraction_test.py
index 1d862f95d..38b0b0387 100644
--- a/browser_use/dom/tests/extraction_test.py
+++ b/browser_use/dom/tests/extraction_test.py
@@ -87,6 +87,9 @@ async def test_process_html_file():
await page.evaluate('document.getElementById("playwright-highlight-container")?.remove()')
+TIMEOUT = 60
+
+
async def test_focus_vs_all_elements():
config = BrowserContextConfig(
# cookies_file='cookies3.json',
@@ -103,8 +106,8 @@ async def test_focus_vs_all_elements():
websites = [
'https://en.wikipedia.org/wiki/Humanist_Party_of_Ontario',
- 'https://www.google.com/travel/flights?tfs=CBwQARoJagcIARIDTEpVGglyBwgBEgNMSlVAAUgBcAGCAQsI____________AZgBAQ&tfu=KgIIAw&hl=en-US&gl=US',
- # 'https://www.concur.com/?&cookie_preferences=cpra',
+ # 'https://www.google.com/travel/flights?tfs=CBwQARoJagcIARIDTEpVGglyBwgBEgNMSlVAAUgBcAGCAQsI____________AZgBAQ&tfu=KgIIAw&hl=en-US&gl=US',
+ # # 'https://www.concur.com/?&cookie_preferences=cpra',
'https://immobilienscout24.de',
'https://docs.google.com/spreadsheets/d/1INaIcfpYXlMRWO__de61SHFCaqt1lfHlcvtXZPItlpI/edit',
'https://www.zeiss.com/career/en/job-search.html?page=1',
@@ -145,7 +148,21 @@ async def test_focus_vs_all_elements():
print(all_elements_state.element_tree.clickable_elements_to_string())
- answer = input('Press Enter to clear highlights and continue...')
+ try:
+ # Set timeout of 5 seconds for input
+ import signal
+
+ def timeout_handler(signum, frame):
+ raise TimeoutError()
+
+ signal.signal(signal.SIGALRM, timeout_handler)
+ signal.alarm(TIMEOUT)
+
+ answer = input(f'Press Enter to clear highlights and continue ({TIMEOUT}s timeout)...')
+ signal.alarm(0) # Cancel the alarm if input received
+ except TimeoutError:
+ answer = None
+ print('Timeout reached, continuing automatically...')
if answer == 'q':
break