safari_inspect_element
Inspect DOM elements and retrieve their properties using a CSS selector and session ID, enabling browser automation and development tasks with Safari MCP Server.
Instructions
Inspect a DOM element and get its properties
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | CSS selector for the element | |
| sessionId | Yes | Session identifier |
Implementation Reference
- src/safari-driver.ts:308-349 (handler)Core handler implementation: Finds the DOM element using Selenium WebDriver's findElement with CSS selector, retrieves tag name, text content, attributes via executeScript, and bounding rectangle. Returns ElementInspectionResult.async inspectElement(sessionId: string, selector: string): Promise<ElementInspectionResult> { const session = this.getSession(sessionId); if (!session) { throw new Error(`Session ${sessionId} not found`); } try { const element = await session.driver.findElement(By.css(selector)); const [tagName, text, attributes, boundingRect] = await Promise.all([ element.getTagName(), element.getText(), session.driver.executeScript(` const el = arguments[0]; const attrs = {}; for (let attr of el.attributes) { attrs[attr.name] = attr.value; } return attrs; `, element), session.driver.executeScript(` const rect = arguments[0].getBoundingClientRect(); return { x: rect.x, y: rect.y, width: rect.width, height: rect.height }; `, element) ]); return { tagName, text: text.substring(0, 500), // Limit text length attributes, boundingRect }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); throw new Error(`Element inspection failed: ${errorMessage}`); } }
- src/safari-mcp-server.ts:361-372 (handler)MCP server wrapper handler: Delegates to SafariDriverManager.inspectElement and formats the result as MCP text content.private async inspectElement(args: Record<string, any>): Promise<Array<{ type: string; text: string }>> { const { sessionId, selector } = args; const elementInfo = await this.driverManager.inspectElement(sessionId, selector); return [ { type: 'text', text: `Element inspection for selector '${selector}':\n\n${JSON.stringify(elementInfo, null, 2)}` } ]; }
- src/safari-mcp-server.ts:164-175 (schema)Tool schema definition including input schema with sessionId and selector parameters.{ name: 'safari_inspect_element', description: 'Inspect a DOM element and get its properties', inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'Session identifier' }, selector: { type: 'string', description: 'CSS selector for the element' } }, required: ['sessionId', 'selector'] } },
- src/safari-mcp-server.ts:249-250 (registration)Tool registration in the handleToolCall switch statement, dispatching to the inspectElement handler.case 'safari_inspect_element': return await this.inspectElement(args);