getForms
Extract all form elements from a webpage to analyze structure, collect data, or automate interactions during browser automation 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)The main handler function getForms() in PlaywrightController class that uses page.evaluate to extract all forms, their action/method, and input fields from the current page.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)The Tool schema definition for 'getForms', specifying no input parameters.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 tools dictionary passed to MCP server capabilities.getForms: GET_FORMS_TOOL,
- src/server.ts:740-745 (registration)Dispatch handler in callTool request handler that invokes the getForms method and returns the JSON stringified result.case 'getForms': { const forms = await playwrightController.getForms(); return { content: [{ type: "text", text: JSON.stringify(forms, null, 2) }] }; }