browser_state
Retrieve current browser session details including session ID, URL, page title, and window information to monitor or verify browser state.
Instructions
Return session id, URL, title, and window information.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/selenium_mcp_server/server.py:53-56 (registration)Tool 'browser_state' registered with @mcp.tool() decorator, calls browser.state via _run helper.
@mcp.tool() def browser_state() -> dict[str, Any]: """Return session id, URL, title, and window information.""" return _run("browser_state", browser.state) - src/selenium_mcp_server/server.py:53-56 (handler)The handler function browser_state() returns the result of calling browser.state, wrapped by _run for error handling.
@mcp.tool() def browser_state() -> dict[str, Any]: """Return session id, URL, title, and window information.""" return _run("browser_state", browser.state) - Pydantic model BrowserState defines the schema: session_id, current_url, title, window_handles, active_window_handle.
class BrowserState(BaseModel): session_id: str | None current_url: str | None title: str | None window_handles: list[str] active_window_handle: str | None - BrowserManager.state() method constructs a BrowserState by reading driver's session_id, current_url, title, window_handles, and active_window_handle.
def state(self) -> BrowserState: with self._lock: if self._driver is None: return BrowserState( session_id=None, current_url=None, title=None, window_handles=[], active_window_handle=None, ) return BrowserState( session_id=str(self._driver.session_id), current_url=self._driver.current_url, title=self._driver.title, window_handles=list(self._driver.window_handles), active_window_handle=self._driver.current_window_handle, )