@@ -8,7 +8,7 @@ import z from 'zod';
88import { defineTool } from './ToolDefinition.js' ;
99import { ElementHandle } from 'puppeteer-core' ;
1010import { ToolCategories } from './categories.js' ;
11- import { performAction } from '../performAction .js' ;
11+ import { waitForEventsAfterAction } from '../waitForHelpers .js' ;
1212
1313export const click = defineTool ( {
1414 name : 'click' ,
@@ -32,7 +32,7 @@ export const click = defineTool({
3232 const uid = request . params . uid ;
3333 const handle = await context . getElementByUid ( uid ) ;
3434 try {
35- await performAction ( handle . frame . page ( ) , async ( ) => {
35+ await waitForEventsAfterAction ( handle . frame . page ( ) , async ( ) => {
3636 await handle . asLocator ( ) . click ( {
3737 count : request . params . dblClick ? 2 : 1 ,
3838 } ) ;
@@ -67,7 +67,9 @@ export const hover = defineTool({
6767 const uid = request . params . uid ;
6868 const handle = await context . getElementByUid ( uid ) ;
6969 try {
70- await handle . asLocator ( ) . hover ( ) ;
70+ await waitForEventsAfterAction ( handle . frame . page ( ) , async ( ) => {
71+ await handle . asLocator ( ) . hover ( ) ;
72+ } ) ;
7173 response . appendResponseLine ( `Successfully hovered over the element` ) ;
7274 response . setIncludeSnapshot ( true ) ;
7375 } finally {
@@ -92,10 +94,11 @@ export const fill = defineTool({
9294 value : z . string ( ) . describe ( 'The value to fill in' ) ,
9395 } ,
9496 handler : async ( request , response , context ) => {
95- const uid = request . params . uid ;
96- const handle = await context . getElementByUid ( uid ) ;
97+ const handle = await context . getElementByUid ( request . params . uid ) ;
9798 try {
98- await handle . asLocator ( ) . fill ( request . params . value ) ;
99+ await waitForEventsAfterAction ( handle . frame . page ( ) , async ( ) => {
100+ await handle . asLocator ( ) . fill ( request . params . value ) ;
101+ } ) ;
99102 response . appendResponseLine ( `Successfully filled out the element` ) ;
100103 response . setIncludeSnapshot ( true ) ;
101104 } finally {
@@ -119,9 +122,11 @@ export const drag = defineTool({
119122 const fromHandle = await context . getElementByUid ( request . params . from_uid ) ;
120123 const toHandle = await context . getElementByUid ( request . params . to_uid ) ;
121124 try {
122- await fromHandle . drag ( toHandle ) ;
123- await new Promise ( resolve => setTimeout ( resolve , 50 ) ) ;
124- await toHandle . drop ( fromHandle ) ;
125+ await waitForEventsAfterAction ( fromHandle . frame . page ( ) , async ( ) => {
126+ await fromHandle . drag ( toHandle ) ;
127+ await new Promise ( resolve => setTimeout ( resolve , 50 ) ) ;
128+ await toHandle . drop ( fromHandle ) ;
129+ } ) ;
125130 response . appendResponseLine ( `Successfully dragged an element` ) ;
126131 response . setIncludeSnapshot ( true ) ;
127132 } finally {
@@ -152,7 +157,9 @@ export const fillForm = defineTool({
152157 for ( const element of request . params . elements ) {
153158 const handle = await context . getElementByUid ( element . uid ) ;
154159 try {
155- await handle . asLocator ( ) . fill ( element . value ) ;
160+ await waitForEventsAfterAction ( handle . frame . page ( ) , async ( ) => {
161+ await handle . asLocator ( ) . fill ( element . value ) ;
162+ } ) ;
156163 } finally {
157164 handle . dispose ( ) ;
158165 }
0 commit comments