take_snapshot
Capture the accessibility tree of the current page for token-efficient analysis in dynamic debugging.
Instructions
Get the accessibility tree of the current page (token-efficient).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The take_snapshot handler function. Uses @mcp.tool() decorator. First tries Playwright's accessibility.snapshot(), falls back to a JS walk() of the DOM to build an accessibility tree (role, name, value, text, children). Returns {'snapshot': ...} or {'error': ...}.
@mcp.tool() async def take_snapshot() -> dict: """Get the accessibility tree of the current page (token-efficient).""" try: page = await browser_manager.get_active_page() try: snapshot = await page.accessibility.snapshot() except AttributeError: snapshot = await page.evaluate("""() => { function walk(node) { if (!node) return null; const item = {}; const tag = node.tagName ? node.tagName.toLowerCase() : ''; const role = node.getAttribute ? (node.getAttribute('role') || tag) : ''; if (role) item.role = role; const name = node.getAttribute ? (node.getAttribute('aria-label') || node.getAttribute('alt') || node.getAttribute('title') || (node.tagName === 'INPUT' ? node.getAttribute('placeholder') : '') || '') : ''; if (name) item.name = name; if (['INPUT','TEXTAREA','SELECT'].includes(node.tagName)) item.value = node.value || ''; const text = [], children = []; for (const child of (node.childNodes || [])) { if (child.nodeType === 3) { const t = child.textContent.trim(); if (t) text.push(t); } else if (child.nodeType === 1) { const c = walk(child); if (c) children.push(c); } } if (text.length && !children.length) item.text = text.join(' '); if (children.length) item.children = children; if (!item.role && !item.name && !item.text && !children.length) return null; return item; } return walk(document.body); }""") return {"snapshot": snapshot} except Exception as e: return {"error": str(e)} - src/camoufox_reverse_mcp/server.py:4-10 (registration)FastMCP instance ('camoufox-reverse-mcp') created here. The @mcp.tool() decorator on take_snapshot registers it with this server.
mcp = FastMCP( "camoufox-reverse-mcp", instructions="Anti-detection browser MCP server for JavaScript reverse engineering. " "Uses Camoufox (C++ engine-level fingerprint spoofing) to bypass bot detection " "while performing JS analysis, debugging, hooking, network interception, " "and JSVMP bytecode analysis." ) - src/camoufox_reverse_mcp/server.py:15-15 (registration)The navigation module (containing take_snapshot) is imported and registered as part of the server's tool set.
from .tools import navigation # noqa: E402, F401 — browser control + page interaction