Skip to content

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

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.py
index 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 service
if 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.py
index 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_session
self.logger = logger or browser_session.logger
+ self.cross_origin_iframes = cross_origin_iframes
async 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 target
frame_id = node.get('frameId', None)
diff --git a/browser_use/logging_config.py b/browser_use/logging_config.py
index 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 level
cdp_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