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
move cross-origin iframe option to instance attr instead of hardcoded global
Nick Sweeting5668ab3f9be3
diff --git a/browser_use/browser/watchdogs/dom_watchdog.py b/browser_use/browser/watchdogs/dom_watchdog.pyindex 54210b7a9..f17bfbd0c 100644--- a/browser_use/browser/watchdogs/dom_watchdog.py+++ b/browser_use/browser/watchdogs/dom_watchdog.py@@ -411,7 +411,11 @@ class DOMWatchdog(BaseWatchdog):# Create or reuse DOM serviceif self._dom_service is None:# self.logger.debug('π DOMWatchdog._build_dom_tree: Creating DomService...')- self._dom_service = DomService(browser_session=self.browser_session, logger=self.logger)+ self._dom_service = DomService(+ browser_session=self.browser_session,+ logger=self.logger,+ cross_origin_iframes=self.browser_session.browser_profile.cross_origin_iframes,+ )# self.logger.debug('π DOMWatchdog._build_dom_tree: β DomService created')# else:# self.logger.debug('π DOMWatchdog._build_dom_tree: Reusing existing DomService')diff --git a/browser_use/dom/service.py b/browser_use/dom/service.pyindex a326708e2..a5bdfe2e7 100644--- a/browser_use/dom/service.py+++ b/browser_use/dom/service.py@@ -28,10 +28,6 @@ if TYPE_CHECKING:from browser_use.browser.session import BrowserSession-# TODO: enable cross origin iframes -> experimental for now-ENABLE_CROSS_ORIGIN_IFRAMES = False--class DomService:"""Service for getting the DOM tree and other DOM-related information.@@ -43,9 +39,10 @@ class DomService:logger: logging.Logger- def __init__(self, browser_session: 'BrowserSession', logger: logging.Logger | None = None):+ def __init__(self, browser_session: 'BrowserSession', logger: logging.Logger | None = None, cross_origin_iframes: bool = False):self.browser_session = browser_sessionself.logger = logger or browser_session.logger+ self.cross_origin_iframes = cross_origin_iframesasync def __aenter__(self):return self@@ -616,7 +613,7 @@ class DomService:if (# TODO: hacky way to disable cross origin iframes for now- ENABLE_CROSS_ORIGIN_IFRAMES and node['nodeName'].upper() == 'IFRAME' and node.get('contentDocument', None) is None+ self.cross_origin_iframes and node['nodeName'].upper() == 'IFRAME' and node.get('contentDocument', None) is None): # None meaning there is no content# Use get_all_frames to find the iframe's targetframe_id = node.get('frameId', None)diff --git a/browser_use/logging_config.py b/browser_use/logging_config.pyindex 73d8ac627..34bb5bacf 100644--- a/browser_use/logging_config.py+++ b/browser_use/logging_config.py@@ -150,7 +150,7 @@ def setup_logging(stream=None, log_level=None, force_setup=False):# Convert CDP_LOGGING_LEVEL string to logging levelcdp_level_str = CONFIG.CDP_LOGGING_LEVEL.upper()cdp_level = getattr(logging, cdp_level_str, logging.WARNING)-+try:from cdp_use.logging import setup_cdp_logging # type: ignore