getForms
Extract all forms from a webpage using PlayMCP Browser Automation Server, enabling efficient data collection and web automation for scraping or testing tasks.
Instructions
Get all forms from the current page
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/controllers/playwright.ts:439-463 (handler)Core handler function in PlaywrightController that extracts all forms from the current page, including action, method, and field details using browser evaluation.async getForms(): Promise<Array<{action?: string, method?: string, fields: Array<{name?: string, type?: string, value?: string}>}>> { try { if (!this.isInitialized()) { throw new Error('Browser not initialized'); } this.log('Getting page forms'); const forms = await this.state.page?.evaluate(() => { const formElements = Array.from(document.querySelectorAll('form')); return formElements.map(form => ({ action: form.getAttribute('action') || undefined, method: form.getAttribute('method') || undefined, fields: Array.from(form.querySelectorAll('input, select, textarea')).map(field => ({ name: field.getAttribute('name') || undefined, type: field.getAttribute('type') || field.tagName.toLowerCase(), value: (field as HTMLInputElement).value || undefined })) })); }); this.log('Forms retrieved:', forms?.length); return forms || []; } catch (error: any) { console.error('Get forms error:', error); throw new BrowserError('Failed to get forms', 'Check if the page is loaded'); } }
- src/server.ts:173-181 (schema)Tool schema definition specifying the name, description, and empty input schema (no parameters required) for the getForms tool.const GET_FORMS_TOOL: Tool = { name: "getForms", description: "Get all forms from the current page", inputSchema: { type: "object", properties: {}, required: [] } };
- src/server.ts:531-531 (registration)Registration of the getForms tool in the central tools object provided to the MCP server's capabilities.getForms: GET_FORMS_TOOL,
- src/server.ts:740-745 (handler)MCP tool call dispatcher that invokes the getForms handler from the controller and formats the response as JSON.case 'getForms': { const forms = await playwrightController.getForms(); return { content: [{ type: "text", text: JSON.stringify(forms, null, 2) }] }; }