@@ -10,6 +10,7 @@ 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 { appendNavigatedToUrl } from '../WaitForHelper.js' ;
1314
1415import { ToolCategory } from './categories.js' ;
1516import type { ContextPage } from './ToolDefinition.js' ;
@@ -63,7 +64,7 @@ export const click = definePageTool({
6364 const uid = request . params . uid ;
6465 const handle = await request . page . getElementByUid ( uid ) ;
6566 try {
66- await request . page . waitForEventsAfterAction ( async ( ) => {
67+ const result = await request . page . waitForEventsAfterAction ( async ( ) => {
6768 await handle . asLocator ( ) . click ( {
6869 count : request . params . dblClick ? 2 : 1 ,
6970 } ) ;
@@ -73,6 +74,7 @@ export const click = definePageTool({
7374 ? `Successfully double clicked on the element`
7475 : `Successfully clicked on the element` ,
7576 ) ;
77+ appendNavigatedToUrl ( response , result ) ;
7678 if ( request . params . includeSnapshot ) {
7779 response . includeSnapshot ( ) ;
7880 }
@@ -101,7 +103,7 @@ export const clickAt = definePageTool({
101103 blockedByDialog : true ,
102104 handler : async ( request , response ) => {
103105 const page = request . page ;
104- await page . waitForEventsAfterAction ( async ( ) => {
106+ const result = await page . waitForEventsAfterAction ( async ( ) => {
105107 await page . pptrPage . mouse . click ( request . params . x , request . params . y , {
106108 clickCount : request . params . dblClick ? 2 : 1 ,
107109 } ) ;
@@ -111,6 +113,7 @@ export const clickAt = definePageTool({
111113 ? `Successfully double clicked at the coordinates`
112114 : `Successfully clicked at the coordinates` ,
113115 ) ;
116+ appendNavigatedToUrl ( response , result ) ;
114117 if ( request . params . includeSnapshot ) {
115118 response . includeSnapshot ( ) ;
116119 }
@@ -137,10 +140,11 @@ export const hover = definePageTool({
137140 const uid = request . params . uid ;
138141 const handle = await request . page . getElementByUid ( uid ) ;
139142 try {
140- await request . page . waitForEventsAfterAction ( async ( ) => {
143+ const result = await request . page . waitForEventsAfterAction ( async ( ) => {
141144 await handle . asLocator ( ) . hover ( ) ;
142145 } ) ;
143146 response . appendResponseLine ( `Successfully hovered over the element` ) ;
147+ appendNavigatedToUrl ( response , result ) ;
144148 if ( request . params . includeSnapshot ) {
145149 response . includeSnapshot ( ) ;
146150 }
@@ -239,7 +243,7 @@ export const fill = definePageTool({
239243 blockedByDialog : true ,
240244 handler : async ( request , response , context ) => {
241245 const page = request . page ;
242- await page . waitForEventsAfterAction ( async ( ) => {
246+ const result = await page . waitForEventsAfterAction ( async ( ) => {
243247 await fillFormElement (
244248 request . params . uid ,
245249 request . params . value ,
@@ -248,6 +252,7 @@ export const fill = definePageTool({
248252 ) ;
249253 } ) ;
250254 response . appendResponseLine ( `Successfully filled out the element` ) ;
255+ appendNavigatedToUrl ( response , result ) ;
251256 if ( request . params . includeSnapshot ) {
252257 response . includeSnapshot ( ) ;
253258 }
@@ -268,7 +273,7 @@ export const typeText = definePageTool({
268273 blockedByDialog : true ,
269274 handler : async ( request , response ) => {
270275 const page = request . page ;
271- await page . waitForEventsAfterAction ( async ( ) => {
276+ const result = await page . waitForEventsAfterAction ( async ( ) => {
272277 await page . pptrPage . keyboard . type ( request . params . text ) ;
273278 if ( request . params . submitKey ) {
274279 await page . pptrPage . keyboard . press (
@@ -279,6 +284,7 @@ export const typeText = definePageTool({
279284 response . appendResponseLine (
280285 `Typed text "${ request . params . text } ${ request . params . submitKey ? ` + ${ request . params . submitKey } ` : '' } "` ,
281286 ) ;
287+ appendNavigatedToUrl ( response , result ) ;
282288 } ,
283289} ) ;
284290
@@ -301,12 +307,13 @@ export const drag = definePageTool({
301307 ) ;
302308 const toHandle = await request . page . getElementByUid ( request . params . to_uid ) ;
303309 try {
304- await request . page . waitForEventsAfterAction ( async ( ) => {
310+ const result = await request . page . waitForEventsAfterAction ( async ( ) => {
305311 await fromHandle . drag ( toHandle ) ;
306312 await new Promise ( resolve => setTimeout ( resolve , 50 ) ) ;
307313 await toHandle . drop ( fromHandle ) ;
308314 } ) ;
309315 response . appendResponseLine ( `Successfully dragged an element` ) ;
316+ appendNavigatedToUrl ( response , result ) ;
310317 if ( request . params . includeSnapshot ) {
311318 response . includeSnapshot ( ) ;
312319 }
@@ -339,17 +346,22 @@ export const fillForm = definePageTool({
339346 blockedByDialog : true ,
340347 handler : async ( request , response , context ) => {
341348 const page = request . page ;
349+ let lastResult : { navigatedToUrl ?: string } = { } ;
342350 for ( const element of request . params . elements ) {
343- await page . waitForEventsAfterAction ( async ( ) => {
351+ const result = await page . waitForEventsAfterAction ( async ( ) => {
344352 await fillFormElement (
345353 element . uid ,
346354 element . value ,
347355 context as McpContext ,
348356 page ,
349357 ) ;
350358 } ) ;
359+ if ( result . navigatedToUrl ) {
360+ lastResult = result ;
361+ }
351362 }
352363 response . appendResponseLine ( `Successfully filled out the form` ) ;
364+ appendNavigatedToUrl ( 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+ appendNavigatedToUrl ( response , result ) ;
445458 if ( request . params . includeSnapshot ) {
446459 response . includeSnapshot ( ) ;
447460 }
0 commit comments