Skip to content

Fix builtin browser failing to start with 'NoneType' object has no attribute 'browser_type' - #2104

Open
Liang-HZ wants to merge 1 commit into
unclecode:mainfrom
Liang-HZ:fix/builtin-browser-managedbrowser-config
Open

Fix builtin browser failing to start with 'NoneType' object has no attribute 'browser_type'#2104
Liang-HZ wants to merge 1 commit into
unclecode:mainfrom
Liang-HZ:fix/builtin-browser-managedbrowser-config

Conversation

@Liang-HZ

Copy link
Copy Markdown

Summary

crwl browser start and BrowserProfiler.launch_builtin_browser() fail unconditionally with:

Error starting builtin browser: 'NoneType' object has no attribute 'browser_type'

ManagedBrowser.__init__ still declares — and documents — the legacy keyword
arguments (browser_type, user_data_dir, headless, host, debugging_port,
cdp_url), but its body reads every value from browser_config, which defaults
to None:

def __init__(self, browser_type="chromium", user_data_dir=None, headless=False,
             logger=None, host="localhost", debugging_port=9222,
             cdp_url=None, browser_config: Optional[BrowserConfig] = None):
    ...
    self.browser_type = browser_config.browser_type   # AttributeError when None

launch_builtin_browser() is the one caller that still passes only the legacy
kwargs, so it raises every time. The two other call sites in the same file were
already migrated to browser_config= (the old kwargs are still sitting there
commented out), which suggests this one was simply missed during the refactor.

Fix

Two small changes:

  1. browser_profiler.pylaunch_builtin_browser() now builds a BrowserConfig
    and passes it, matching the two sibling call sites in the same file.
  2. browser_manager.pyManagedBrowser.__init__ falls back to the documented
    legacy keyword arguments when browser_config is None, instead of raising an
    opaque AttributeError. This keeps the published signature honest and protects
    any third-party code still calling it the old way.

Reproduction

Before:

$ crwl browser start
Error starting builtin browser: 'NoneType' object has no attribute 'browser_type'

After:

$ crwl browser start
[BUILTIN]. ℹ Builtin browser launched at CDP URL: http://localhost:9222
╭─────────────────────── Builtin Browser Start ───────────────────────╮
│ Builtin browser started successfully                                │
│ CDP URL: http://localhost:9222                                      │
╰─────────────────────────────────────────────────────────────────────╯

crwl browser status / crwl browser stop and BrowserConfig(browser_mode="builtin")
work against the started instance afterwards.

Also verified that constructing ManagedBrowser(...) with only the legacy kwargs
no longer raises, and that passing browser_config= behaves exactly as before.

Related issues

Verified against main at the time of writing: both the missing browser_config
in launch_builtin_browser() and the unconditional browser_config.* reads in
ManagedBrowser.__init__ are still present.

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 unclecode#1139, unclecode#1142
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant