Skip to content

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

boundaries and adding attributes

Gregor Žunič075d03bc9bcf
diff --git a/browser_use/dom/process_dom.js b/browser_use/dom/process_dom.js
index 9ec03f211..58178a491 100644
--- a/browser_use/dom/process_dom.js
+++ b/browser_use/dom/process_dom.js
@@ -6,9 +6,7 @@
while (currentElement && currentElement.nodeType === Node.ELEMENT_NODE) {
// Stop if we hit a shadow root or iframe
- if (stopAtBoundary &&
- (currentElement.parentNode instanceof ShadowRoot ||
- currentElement.parentNode instanceof HTMLIFrameElement)) {
+ if (stopAtBoundary && (currentElement.parentNode instanceof ShadowRoot || currentElement.parentNode instanceof HTMLIFrameElement)) {
break;
}
@@ -55,6 +53,13 @@
children: []
};
+ // Copy all attributes if the node is an element
+ if (node.nodeType === Node.ELEMENT_NODE && node.attributes) {
+ for (const attr of node.attributes) {
+ nodeData.attributes[attr.name] = attr.value;
+ }
+ }
+
// Only add iframeContext if we're inside an iframe
if (parentIframe) {
nodeData.iframeContext = `iframe[src="${parentIframe.src || ''}"]`;
diff --git a/browser_use/dom/tests/process_dom_test.py b/browser_use/dom/tests/process_dom_test.py
index 36badb54d..f7d19dcd1 100644
--- a/browser_use/dom/tests/process_dom_test.py
+++ b/browser_use/dom/tests/process_dom_test.py
@@ -14,7 +14,8 @@ async def test_process_dom():
# await page.goto('https://kayak.com/flights')
# browser.go_to_url('https://google.com/flights')
- await page.goto('https://immobilienscout24.de')
+ # await page.goto('https://immobilienscout24.de')
+ await page.goto('https://www.w3schools.com/html/html_iframe.asp')
time.sleep(1.5)
@@ -32,4 +33,10 @@ async def test_process_dom():
with open('./tmp/dom.json', 'w') as f:
json.dump(dom_tree, f, indent=1)
+ # both of these work for immobilienscout24.de
+ # await page.click('.sc-dcJsrY.ezjNCe')
+ # await page.click(
+ # 'div > div:nth-of-type(2) > div > div:nth-of-type(2) > div > div:nth-of-type(2) > div > div > div > button:nth-of-type(2)'
+ # )
+
input('Press Enter to continue...')