unclecode/crawl4ai · error · RuntimeError
Browser is not available. It may have been closed, crashed,
Error message
Browser is not available. It may have been closed, crashed, or not yet started. Ensure the browser is running before creating new contexts.
What it means
The sibling guard in create_browser_context(): self.browser is None and the manager was NOT launched persistently, meaning the Playwright Browser handle is gone — it was never started, was closed, or crashed. Any subsequent context/session creation hits this RuntimeError.
Source
Thrown at crawl4ai/browser_manager.py:1268
for script in self.config.init_scripts:
await context.add_init_script(script)
async def create_browser_context(self, crawlerRunConfig: CrawlerRunConfig = None):
"""
Creates and returns a new browser context with configured settings.
Applies text-only mode settings if text_mode is enabled in config.
Returns:
Context: Browser context object with the specified configurations
"""
if self.browser is None:
if self._launched_persistent:
raise RuntimeError(
"Cannot create new browser contexts when using "
"use_persistent_context=True. Persistent context uses a "
"single shared context."
)
raise RuntimeError(
"Browser is not available. It may have been closed, crashed, "
"or not yet started. Ensure the browser is running before "
"creating new contexts."
)
# Base settings
user_agent = self.config.headers.get("User-Agent", self.config.user_agent)
viewport_settings = {
"width": self.config.viewport_width,
"height": self.config.viewport_height,
}
proxy_settings = {"server": self.config.proxy} if self.config.proxy else None
# CSS extensions (blocked separately via avoid_css flag)
css_extensions = ["css", "less", "scss", "sass"]
# Static resource extensions (blocked when text_mode is enabled)
static_extensions = [
# ImagesView on GitHub (pinned to 7e80152142)
Solutions
- Use the crawler inside its lifecycle: async with AsyncWebCrawler() as crawler: await crawler.arun(...) — it auto-starts.
- If you manage lifecycle manually, await crawler.start() before use and don't call methods after close().
- Create a fresh AsyncWebCrawler instance per batch instead of reusing a closed one.
- Check earlier logs for the browser crash/stop reason (startup failure, OOM) and fix that first.
Example fix
# before
crawler = AsyncWebCrawler()
await crawler.start()
await crawler.close()
results = await crawler.arun(url) # RuntimeError: browser not available
# after
async with AsyncWebCrawler() as crawler:
results = await crawler.arun(url) Defensive patterns
Strategy: validation
Validate before calling
if crawler.crawler_strategy.browser is None and not crawler.ready:
await crawler.start() # or refuse to proceed Type guard
async def is_crawler_ready(crawler) -> bool:
return bool(getattr(crawler, 'ready', False)) or (
getattr(crawler.crawler_strategy, 'browser', None) is not None
) Try / catch
try:
results = await crawler.arun(url)
except RuntimeError as e:
if 'Browser is not available' in str(e):
crawler = AsyncWebCrawler(config=browser_config) # fresh instance
async with crawler:
results = await crawler.arun(url)
else:
raise Prevention
- Always use 'async with AsyncWebCrawler() as crawler' scoping.
- Never call crawler methods after close().
- Create a new instance per batch rather than resurrecting closed ones.
When it happens
Trigger: Calling crawler.arun() after __aexit__ closed the browser; reusing a crawler instance after its browser crashed (see 'Failed to start browser'); calling internal APIs before awaiting crawler.start(); using a manager whose cleanup() already ran.
Common situations: Reusing an AsyncWebCrawler outside its async with block; forgetting await crawler.start() when calling low-level strategy methods; background tasks racing with shutdown; browser process killed by OOM.
Related errors
- Invalid URL, make sure the URL is a non-empty string
- Process HTML, Failed to extract content from the website: {u
- Process HTML, Failed to extract content from the website: {u
- psutil not available, cannot clean old browser
- Failed to start browser: {e}
AI-assisted analysis of unclecode/crawl4ai@7e80152142 (2026-08-14).
Data as JSON: /api/errors/0251bff83bb12388.
Report an issue: GitHub.