diff --git a/src/backends/idb-backend.test.ts b/src/backends/idb-backend.test.ts index 7b3fc90..8013005 100644 --- a/src/backends/idb-backend.test.ts +++ b/src/backends/idb-backend.test.ts @@ -2850,6 +2850,16 @@ describe('IdbBackend keys and buttons', () => { ); }); + it('only clears the field for an empty string', async () => { + await backend.typeText(''); + + // `idb ui text ""` exits 1, so it is skipped like the ADB backend does. + expect(idbCalls()).toStrictEqual([ + ['ui', 'key', '4', '--command', '--udid', udid], + ['ui', 'key', '42', '--udid', udid], + ]); + }); + it('presses Return to dismiss a visible keyboard', async () => { mockExecStrict.mockImplementation(async (_cmd, args) => args?.[1] === 'describe-all' ? hierarchyWith(['Keyboard']) : '', diff --git a/src/backends/idb-backend.ts b/src/backends/idb-backend.ts index 8a7a3a2..383325d 100644 --- a/src/backends/idb-backend.ts +++ b/src/backends/idb-backend.ts @@ -733,6 +733,10 @@ export class IdbBackend implements DeviceBackend { * strict execution so a failed clear rejects instead of appending to the * old value. On an empty field the two keys do nothing. * + * Empty text stops after the clear: `idb ui text ""` exits 1 with + * "Request was not sent", and the field is already empty. This matches the + * ADB backend. + * * @param text - The text to type. */ async typeText(text: string): Promise { @@ -752,6 +756,9 @@ export class IdbBackend implements DeviceBackend { '--udid', this.#udid, ]); + if (text.length === 0) { + return; + } await this.#execStrict(this.#idbPath, [ 'ui', 'text', diff --git a/src/tools/type-text.ts b/src/tools/type-text.ts index b8fc1ee..aed3f30 100644 --- a/src/tools/type-text.ts +++ b/src/tools/type-text.ts @@ -15,8 +15,8 @@ export function registerTypeTool( description: 'Type text into the currently focused input field. ' + 'Tap an input element first to focus it, then call this. ' + - 'The field is cleared before typing on all backends. On Android ' + - '(adb), an empty string clears the field.', + 'The field is cleared before typing on all backends. An empty ' + + 'string only clears the field.', inputSchema: { text: z.string().describe('Text to type'), },