From a928f0075b1095e66b01d09967dc0dbaf7ada704 Mon Sep 17 00:00:00 2001 From: Liang-HZ <36034777+Liang-HZ@users.noreply.github.com> Date: Mon, 27 Jul 2026 19:33:23 +0800 Subject: [PATCH] Fix builtin browser failing to start with AttributeError ManagedBrowser.__init__ still declares and documents the legacy keyword arguments, but its body reads every value from browser_config, which defaults to None. launch_builtin_browser() is the one caller that still passes only the legacy kwargs, so 'crwl browser start' and BrowserProfiler.launch_builtin_browser() always raise: 'NoneType' object has no attribute 'browser_type' The two sibling call sites in browser_profiler.py were already migrated to browser_config= (the old kwargs remain commented out next to them), so this one appears to have been missed. - launch_builtin_browser() now builds a BrowserConfig and passes it. - ManagedBrowser.__init__ falls back to the documented legacy keyword arguments when browser_config is None, instead of raising an opaque AttributeError. Refs #1139, #1142 --- crawl4ai/browser_manager.py | 13 +++++++++++++ crawl4ai/browser_profiler.py | 7 +++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/crawl4ai/browser_manager.py b/crawl4ai/browser_manager.py index d7b8009c8..98c8ae5ac 100644 --- a/crawl4ai/browser_manager.py +++ b/crawl4ai/browser_manager.py @@ -159,6 +159,19 @@ def __init__( cdp_url (str or None): CDP URL to connect to the browser. Default: None. browser_config (BrowserConfig): Configuration object containing all browser settings. Default: None. """ + if browser_config is None: + # The legacy keyword arguments above are still part of this + # signature and are documented in the docstring; honour them + # instead of raising an opaque AttributeError on ``None``. + browser_config = BrowserConfig( + browser_type=browser_type, + user_data_dir=user_data_dir, + headless=headless, + host=host, + debugging_port=debugging_port, + cdp_url=cdp_url, + ) + self.browser_type = browser_config.browser_type self.user_data_dir = browser_config.user_data_dir self.headless = browser_config.headless diff --git a/crawl4ai/browser_profiler.py b/crawl4ai/browser_profiler.py index c944a596c..6f38768b1 100644 --- a/crawl4ai/browser_profiler.py +++ b/crawl4ai/browser_profiler.py @@ -1202,12 +1202,15 @@ async def launch_builtin_browser(self, os.makedirs(user_data_dir, exist_ok=True) # Create managed browser instance - managed_browser = ManagedBrowser( + browser_config = BrowserConfig( browser_type=browser_type, user_data_dir=user_data_dir, headless=headless, + debugging_port=debugging_port, + ) + managed_browser = ManagedBrowser( + browser_config=browser_config, logger=self.logger, - debugging_port=debugging_port ) try: