@@ -10,6 +10,10 @@ import {zod} from '../third_party/index.js';
1010import type { ElementHandle , KeyInput } from '../third_party/index.js' ;
1111import type { TextSnapshotNode } from '../types.js' ;
1212import { parseKey } from '../utils/keyboard.js' ;
13+ import {
14+ appendWaitForResult ,
15+ type WaitForEventsResult ,
16+ } from '../WaitForHelper.js' ;
1317
1418import { ToolCategory } from './categories.js' ;
1519import type { ContextPage } from './ToolDefinition.js' ;
@@ -63,7 +67,7 @@ export const click = definePageTool({
6367 const uid = request . params . uid ;
6468 const handle = await request . page . getElementByUid ( uid ) ;
6569 try {
66- await request . page . waitForEventsAfterAction ( async ( ) => {
70+ const result = await request . page . waitForEventsAfterAction ( async ( ) => {
6771 await handle . asLocator ( ) . click ( {
6872 count : request . params . dblClick ? 2 : 1 ,
6973 } ) ;
@@ -73,6 +77,7 @@ export const click = definePageTool({
7377 ? `Successfully double clicked on the element`
7478 : `Successfully clicked on the element` ,
7579 ) ;
80+ appendWaitForResult ( response , result ) ;
7681 if ( request . params . includeSnapshot ) {
7782 response . includeSnapshot ( ) ;
7883 }
@@ -101,7 +106,7 @@ export const clickAt = definePageTool({
101106 blockedByDialog : true ,
102107 handler : async ( request , response ) => {
103108 const page = request . page ;
104- await page . waitForEventsAfterAction ( async ( ) => {
109+ const result = await page . waitForEventsAfterAction ( async ( ) => {
105110 await page . pptrPage . mouse . click ( request . params . x , request . params . y , {
106111 clickCount : request . params . dblClick ? 2 : 1 ,
107112 } ) ;
@@ -111,6 +116,7 @@ export const clickAt = definePageTool({
111116 ? `Successfully double clicked at the coordinates`
112117 : `Successfully clicked at the coordinates` ,
113118 ) ;
119+ appendWaitForResult ( response , result ) ;
114120 if ( request . params . includeSnapshot ) {
115121 response . includeSnapshot ( ) ;
116122 }
@@ -137,10 +143,11 @@ export const hover = definePageTool({
137143 const uid = request . params . uid ;
138144 const handle = await request . page . getElementByUid ( uid ) ;
139145 try {
140- await request . page . waitForEventsAfterAction ( async ( ) => {
146+ const result = await request . page . waitForEventsAfterAction ( async ( ) => {
141147 await handle . asLocator ( ) . hover ( ) ;
142148 } ) ;
143149 response . appendResponseLine ( `Successfully hovered over the element` ) ;
150+ appendWaitForResult ( response , result ) ;
144151 if ( request . params . includeSnapshot ) {
145152 response . includeSnapshot ( ) ;
146153 }
@@ -239,7 +246,7 @@ export const fill = definePageTool({
239246 blockedByDialog : true ,
240247 handler : async ( request , response , context ) => {
241248 const page = request . page ;
242- await page . waitForEventsAfterAction ( async ( ) => {
249+ const result = await page . waitForEventsAfterAction ( async ( ) => {
243250 await fillFormElement (
244251 request . params . uid ,
245252 request . params . value ,
@@ -248,6 +255,7 @@ export const fill = definePageTool({
248255 ) ;
249256 } ) ;
250257 response . appendResponseLine ( `Successfully filled out the element` ) ;
258+ appendWaitForResult ( response , result ) ;
251259 if ( request . params . includeSnapshot ) {
252260 response . includeSnapshot ( ) ;
253261 }
@@ -268,7 +276,7 @@ export const typeText = definePageTool({
268276 blockedByDialog : true ,
269277 handler : async ( request , response ) => {
270278 const page = request . page ;
271- await page . waitForEventsAfterAction ( async ( ) => {
279+ const result = await page . waitForEventsAfterAction ( async ( ) => {
272280 await page . pptrPage . keyboard . type ( request . params . text ) ;
273281 if ( request . params . submitKey ) {
274282 await page . pptrPage . keyboard . press (
@@ -279,6 +287,7 @@ export const typeText = definePageTool({
279287 response . appendResponseLine (
280288 `Typed text "${ request . params . text } ${ request . params . submitKey ? ` + ${ request . params . submitKey } ` : '' } "` ,
281289 ) ;
290+ appendWaitForResult ( response , result ) ;
282291 } ,
283292} ) ;
284293
@@ -301,12 +310,13 @@ export const drag = definePageTool({
301310 ) ;
302311 const toHandle = await request . page . getElementByUid ( request . params . to_uid ) ;
303312 try {
304- await request . page . waitForEventsAfterAction ( async ( ) => {
313+ const result = await request . page . waitForEventsAfterAction ( async ( ) => {
305314 await fromHandle . drag ( toHandle ) ;
306315 await new Promise ( resolve => setTimeout ( resolve , 50 ) ) ;
307316 await toHandle . drop ( fromHandle ) ;
308317 } ) ;
309318 response . appendResponseLine ( `Successfully dragged an element` ) ;
319+ appendWaitForResult ( response , result ) ;
310320 if ( request . params . includeSnapshot ) {
311321 response . includeSnapshot ( ) ;
312322 }
@@ -339,8 +349,9 @@ export const fillForm = definePageTool({
339349 blockedByDialog : true ,
340350 handler : async ( request , response , context ) => {
341351 const page = request . page ;
352+ let lastResult : WaitForEventsResult = { } ;
342353 for ( const element of request . params . elements ) {
343- await page . waitForEventsAfterAction ( async ( ) => {
354+ lastResult = await page . waitForEventsAfterAction ( async ( ) => {
344355 await fillFormElement (
345356 element . uid ,
346357 element . value ,
@@ -350,6 +361,7 @@ export const fillForm = definePageTool({
350361 } ) ;
351362 }
352363 response . appendResponseLine ( `Successfully filled out the form` ) ;
364+ appendWaitForResult ( response , lastResult ) ;
353365 if ( request . params . includeSnapshot ) {
354366 response . includeSnapshot ( ) ;
355367 }
@@ -429,7 +441,7 @@ export const pressKey = definePageTool({
429441 const tokens = parseKey ( request . params . key ) ;
430442 const [ key , ...modifiers ] = tokens ;
431443
432- await page . waitForEventsAfterAction ( async ( ) => {
444+ const result = await page . waitForEventsAfterAction ( async ( ) => {
433445 for ( const modifier of modifiers ) {
434446 await page . pptrPage . keyboard . down ( modifier ) ;
435447 }
@@ -442,6 +454,7 @@ export const pressKey = definePageTool({
442454 response . appendResponseLine (
443455 `Successfully pressed key: ${ request . params . key } ` ,
444456 ) ;
457+ appendWaitForResult ( response , result ) ;
445458 if ( request . params . includeSnapshot ) {
446459 response . includeSnapshot ( ) ;
447460 }
0 commit comments