get_console_logs
Retrieve console logs from a page with optional filtering by log level or keyword, and clear the buffer after retrieval.
Instructions
Get console output collected from the page.
Args: level: Filter by log level - "log", "warn", "error", or "info". keyword: Filter logs containing this keyword in the text. clear: If True, clear the log buffer after retrieval.
Returns: List of dicts with level, text, timestamp, and location.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| level | No | ||
| keyword | No | ||
| clear | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- The get_console_logs handler function decorated with @mcp.tool(). Collects console logs from browser_manager._console_logs, with optional filtering by level/keyword and clearing.
@mcp.tool() async def get_console_logs( level: str | None = None, keyword: str | None = None, clear: bool = False, ) -> list[dict]: """Get console output collected from the page. Args: level: Filter by log level - "log", "warn", "error", or "info". keyword: Filter logs containing this keyword in the text. clear: If True, clear the log buffer after retrieval. Returns: List of dicts with level, text, timestamp, and location. """ try: logs = list(browser_manager._console_logs) if level: logs = [l for l in logs if l["level"] == level] if keyword: logs = [l for l in logs if keyword in (l.get("text") or "")] if clear: browser_manager._console_logs.clear() return logs except Exception as e: return [{"error": str(e)}] - src/camoufox_reverse_mcp/server.py:15-19 (registration)The hooking module (which contains get_console_logs) is imported and registered via from .tools import hooking in the server module.
from .tools import navigation # noqa: E402, F401 — browser control + page interaction from .tools import script_analysis # noqa: E402, F401 — scripts() + search_code() from .tools import debugging # noqa: E402, F401 — evaluate_js from .tools import hooking # noqa: E402, F401 — hook_function + inject_hook_preset + remove_hooks from .tools import network # noqa: E402, F401 — network_capture + list/get requests - The _console_logs deque is initialized in BrowserManager.__init__ with a maxlen of 2000, storing collected console messages.
self._console_logs: deque[dict] = deque(maxlen=MAX_LOG_SIZE) - The _on_console method captures console messages from the page and appends them to _console_logs with level, text, timestamp, and location fields.
def _on_console(self, msg) -> None: text = msg.text if text and text.startswith("__MCP_TRACE__:"): try: import json payload = json.loads(text[len("__MCP_TRACE__:"):]) path = payload.pop("__path__", "unknown") self._persistent_traces.setdefault(path, []).append(payload) except Exception: pass return self._console_logs.append({ "level": msg.type, "text": text, "timestamp": int(time.time() * 1000), "location": str(msg.location) if hasattr(msg, "location") else None, }) - The _attach_listeners method registers _on_console as the console event handler on Playwright pages.
def _attach_listeners(self, page: Page) -> None: """Attach console, network, and trace-collection listeners to a page.""" page.on("console", self._on_console) page.on("request", self._on_request)