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
ignore invisible and irrelevant cross-origin-iframes
Nick Sweeting07ad54ca50dd
diff --git a/browser_use/dom/service.py b/browser_use/dom/service.pyindex e18da07b3..2405da168 100644--- a/browser_use/dom/service.py+++ b/browser_use/dom/service.py@@ -47,11 +47,20 @@ class DomService:@time_execution_async('--get_cross_origin_iframes')async def get_cross_origin_iframes(self) -> list[str]:+ # invisible cross-origin iframes are used for ads and tracking, dont open those+ hidden_frame_urls = await self.page.locator('iframe').filter(visible=False).evaluate_all('e => e.map(e => e.src)')++ is_ad_url = lambda url: any(+ domain in urlparse(url).netloc for domain in ('doubleclick.net', 'adroll.com', 'googletagmanager.com')+ )+return [frame.urlfor frame in self.page.framesif urlparse(frame.url).netloc # exclude data:urls and about:blank- and urlparse(frame.url).netloc != urlparse(self.page.url).netloc+ and urlparse(frame.url).netloc != urlparse(self.page.url).netloc # exclude same-origin iframes+ and frame.url not in hidden_frame_urls # exclude hidden frames+ and not is_ad_url(frame.url) # exclude most common ad network tracker frame URLs]@time_execution_async('--build_dom_tree')diff --git a/pyproject.toml b/pyproject.tomlindex 5cb359547..687e0bd5a 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -16,7 +16,7 @@ dependencies = ["python-dotenv>=1.0.1","requests>=2.32.3","posthog>=3.7.0",- "playwright>=1.49.0",+ "playwright>=1.51.0","setuptools>=75.8.0","langchain-core==0.3.35","markdownify==1.1.0",