reset_browser_state
Reset browser state on the MCP server without restarting the browser. Clear hooks, network captures, routes, cookies, and storage as needed.
Instructions
Reset MCP-side browser residual state without closing the browser.
Args: clear_persistent_hooks: Remove all persistent init scripts. clear_network_capture: Clear network request buffer and stop captures. clear_active_routes: Clear instrumentation routes. clear_cookies: ALSO clear browser cookies (destructive; default False). clear_storage: ALSO clear localStorage/sessionStorage (default False).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| clear_persistent_hooks | No | ||
| clear_network_capture | No | ||
| clear_active_routes | No | ||
| clear_cookies | No | ||
| clear_storage | No |
Implementation Reference
- The handler function for the 'reset_browser_state' tool. Clears residual MCP-side browser state including persistent hooks, network captures, instrumentation routes, cookies, and storage, without closing the browser.
@mcp.tool() async def reset_browser_state( clear_persistent_hooks: bool = True, clear_network_capture: bool = True, clear_active_routes: bool = True, clear_cookies: bool = False, clear_storage: bool = False, ) -> dict: """Reset MCP-side browser residual state without closing the browser. Args: clear_persistent_hooks: Remove all persistent init scripts. clear_network_capture: Clear network request buffer and stop captures. clear_active_routes: Clear instrumentation routes. clear_cookies: ALSO clear browser cookies (destructive; default False). clear_storage: ALSO clear localStorage/sessionStorage (default False). """ from typing import Any result: dict[str, Any] = {"status": "reset"} try: if clear_persistent_hooks: try: from .hooking import remove_hooks r = await remove_hooks(keep_persistent=False) result["hooks_removed"] = r except Exception as e: result["hooks_remove_error"] = str(e) if clear_network_capture: count = len(browser_manager._network_requests) browser_manager._network_requests.clear() browser_manager._request_id_counter = 0 browser_manager._capturing = False browser_manager._capture_body = False result["network_requests_cleared"] = count if clear_active_routes: try: from .instrumentation import _active_routes, _stop count = len(_active_routes) await _stop(None) result["instrumentation_routes_cleared"] = count except Exception as e: result["instrumentation_clear_error"] = str(e) if clear_cookies: try: ctx = browser_manager.contexts.get("default") if ctx: await ctx.clear_cookies() result["cookies_cleared"] = True except Exception as e: result["cookies_clear_error"] = str(e) if clear_storage: try: page = await browser_manager.get_active_page() await page.evaluate( "() => { try { localStorage.clear(); } catch(e) {} " "try { sessionStorage.clear(); } catch(e) {} }" ) result["storage_cleared"] = True except Exception as e: result["storage_clear_error"] = str(e) return result except Exception as e: return {"error": str(e)} - src/camoufox_reverse_mcp/tools/navigation.py:371-371 (registration)The @mcp.tool() decorator registers 'reset_browser_state' as an MCP tool on the FastMCP server instance.
@mcp.tool() - Input schema / type definitions for the tool: five boolean parameters with defaults controlling which state to clear.
@mcp.tool() async def reset_browser_state( clear_persistent_hooks: bool = True, clear_network_capture: bool = True, clear_active_routes: bool = True, clear_cookies: bool = False, clear_storage: bool = False, ) -> dict: - launch_browser() warns users about residual state and suggests calling reset_browser_state().
has_residuals = ( len(browser_manager._persistent_scripts) > 0 or len(browser_manager._network_requests) > 0 or len(_active_routes) > 0 ) if has_residuals: result.setdefault("warnings", []).append( "browser already running with residual state. " "Call reset_browser_state() or close_browser() + launch_browser()." ) - check_environment() recommends reset_browser_state() if browser has residual state.
if has_residuals: recommendations.append("Browser has residual state. Consider reset_browser_state().")