diff --git a/src/tools/input.ts b/src/tools/input.ts index 381b19855..cd8b2f4d0 100644 --- a/src/tools/input.ts +++ b/src/tools/input.ts @@ -220,7 +220,6 @@ export const fill = defineTool({ }, handler: async (request, response, context) => { await context.waitForEventsAfterAction(async () => { - await context.getSelectedPage().keyboard.type(request.params.value); await fillFormElement( request.params.uid, request.params.value, diff --git a/tests/tools/input.test.ts b/tests/tools/input.test.ts index 316c8d76f..06a752148 100644 --- a/tests/tools/input.test.ts +++ b/tests/tools/input.test.ts @@ -9,6 +9,7 @@ import fs from 'node:fs/promises'; import path from 'node:path'; import {describe, it} from 'node:test'; +import {McpResponse} from '../../src/McpResponse.js'; import { click, hover, @@ -382,6 +383,79 @@ describe('input', () => { ); }); }); + + it('reproduction: fill isolation', async () => { + await withMcpContext(async (_response, context) => { + const page = context.getSelectedPage(); + await page.setContent( + html`
`, + ); + await context.createTextSnapshot(); + + // Fill email + const response1 = new McpResponse(); + await fill.handler( + { + params: { + uid: '1_1', // email input + value: 'new@test.com', + }, + }, + response1, + context, + ); + assert.strictEqual( + response1.responseLines[0], + 'Successfully filled out the element', + ); + + // Fill password + const response2 = new McpResponse(); + await fill.handler( + { + params: { + uid: '1_2', // password input + value: 'secret', + }, + }, + response2, + context, + ); + assert.strictEqual( + response2.responseLines[0], + 'Successfully filled out the element', + ); + + // Verify values + const values = await page.evaluate(() => { + return { + email: (document.getElementById('email') as HTMLInputElement).value, + password: (document.getElementById('password') as HTMLInputElement) + .value, + }; + }); + + assert.strictEqual( + values.email, + 'new@test.com', + 'Email should be updated correctly', + ); + assert.strictEqual( + values.password, + 'secret', + 'Password should be updated correctly', + ); + }); + }); }); describe('drags', () => {