Registry special-param check rejects PEP 604 `X | None` (only unwraps typing.Union)

Author: michaelkillgtaCreated Sep 25, 2026Updated Sep 25, 2026

Description

In browser_use/tools/registry/service.py (_normalize_action_function_signature), special injected params (browser_session, file_system, page_extraction_llm, available_file_paths, …) are type-checked after optionally unwrapping typing.Union.

PEP 604 unions (BrowserSession | None) use types.UnionType, so unwrapping is skipped and the annotation is compared to the bare expected type → false conflict. typing.Optional[BrowserSession] still works.

Environment

  • browser-use==0.13.10
  • Offline unit repro

Repro

python
from typing import Optional
from browser_use.tools.registry.service import Registry
from browser_use.browser.session import BrowserSession

# OK
def ok(browser_session: Optional[BrowserSession] = None):
    ...

# FAIL — Action parameter conflicts with special argument injected by tools
def bad(browser_session: BrowserSession | None = None):
    ...

Same failure pattern for FileSystem | None, BaseChatModel | None, list[str] | None.

Observed (browser-use==0.13.10)

  • Optional[BrowserSession] = None → OK
  • BrowserSession | None = None → FAIL (conflicts with special argument injected by tools)
  • Same FAIL for other special params with pipe-optional annotations

Expected

X | None should be treated the same as Optional[X] / Union[X, None] for special injected params.

Suggested fix

Unwrap with origin in (Union, UnionType) (import UnionType from types), or use typing.get_args whenever get_origin is a union form. Prefer typing.get_type_hints(func) so stringified annotations under from __future__ import annotations also resolve.

Impact

Custom tool authors on Python 3.10+ using idiomatic pipe unions cannot declare optional browser/FS/LLM injections; registration raises at decorate time and the action never exists for the agent.

Notes

#2475 is a different special-param name clash (page: Page). Happy to open a PR.