@@ -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' ;
@@ -62,7 +63,7 @@ export const click = definePageTool({
6263 const uid = request . params . uid ;
6364 const handle = await request . page . getElementByUid ( uid ) ;
6465 try {
65- await request . page . waitForEventsAfterAction ( async ( ) => {
66+ const result = await request . page . waitForEventsAfterAction ( async ( ) => {
6667 await handle . asLocator ( ) . click ( {
6768 count : request . params . dblClick ? 2 : 1 ,
6869 } ) ;
@@ -72,6 +73,7 @@ export const click = definePageTool({
7273 ? `Successfully double clicked on the element`
7374 : `Successfully clicked on the element` ,
7475 ) ;
76+ appendNavigatedToUrl ( response , result ) ;
7577 if ( request . params . includeSnapshot ) {
7678 response . includeSnapshot ( ) ;
7779 }
@@ -99,7 +101,7 @@ export const clickAt = definePageTool({
99101 } ,
100102 handler : async ( request , response ) => {
101103 const page = request . page ;
102- await page . waitForEventsAfterAction ( async ( ) => {
104+ const result = await page . waitForEventsAfterAction ( async ( ) => {
103105 await page . pptrPage . mouse . click ( request . params . x , request . params . y , {
104106 clickCount : request . params . dblClick ? 2 : 1 ,
105107 } ) ;
@@ -109,6 +111,7 @@ export const clickAt = definePageTool({
109111 ? `Successfully double clicked at the coordinates`
110112 : `Successfully clicked at the coordinates` ,
111113 ) ;
114+ appendNavigatedToUrl ( response , result ) ;
112115 if ( request . params . includeSnapshot ) {
113116 response . includeSnapshot ( ) ;
114117 }
@@ -134,10 +137,11 @@ export const hover = definePageTool({
134137 const uid = request . params . uid ;
135138 const handle = await request . page . getElementByUid ( uid ) ;
136139 try {
137- await request . page . waitForEventsAfterAction ( async ( ) => {
140+ const result = await request . page . waitForEventsAfterAction ( async ( ) => {
138141 await handle . asLocator ( ) . hover ( ) ;
139142 } ) ;
140143 response . appendResponseLine ( `Successfully hovered over the element` ) ;
144+ appendNavigatedToUrl ( response , result ) ;
141145 if ( request . params . includeSnapshot ) {
142146 response . includeSnapshot ( ) ;
143147 }
@@ -235,7 +239,7 @@ export const fill = definePageTool({
235239 } ,
236240 handler : async ( request , response , context ) => {
237241 const page = request . page ;
238- await page . waitForEventsAfterAction ( async ( ) => {
242+ const result = await page . waitForEventsAfterAction ( async ( ) => {
239243 await fillFormElement (
240244 request . params . uid ,
241245 request . params . value ,
@@ -244,6 +248,7 @@ export const fill = definePageTool({
244248 ) ;
245249 } ) ;
246250 response . appendResponseLine ( `Successfully filled out the element` ) ;
251+ appendNavigatedToUrl ( response , result ) ;
247252 if ( request . params . includeSnapshot ) {
248253 response . includeSnapshot ( ) ;
249254 }
@@ -263,7 +268,7 @@ export const typeText = definePageTool({
263268 } ,
264269 handler : async ( request , response ) => {
265270 const page = request . page ;
266- await page . waitForEventsAfterAction ( async ( ) => {
271+ const result = await page . waitForEventsAfterAction ( async ( ) => {
267272 await page . pptrPage . keyboard . type ( request . params . text ) ;
268273 if ( request . params . submitKey ) {
269274 await page . pptrPage . keyboard . press (
@@ -274,6 +279,7 @@ export const typeText = definePageTool({
274279 response . appendResponseLine (
275280 `Typed text "${ request . params . text } ${ request . params . submitKey ? ` + ${ request . params . submitKey } ` : '' } "` ,
276281 ) ;
282+ appendNavigatedToUrl ( response , result ) ;
277283 } ,
278284} ) ;
279285
@@ -295,12 +301,13 @@ export const drag = definePageTool({
295301 ) ;
296302 const toHandle = await request . page . getElementByUid ( request . params . to_uid ) ;
297303 try {
298- await request . page . waitForEventsAfterAction ( async ( ) => {
304+ const result = await request . page . waitForEventsAfterAction ( async ( ) => {
299305 await fromHandle . drag ( toHandle ) ;
300306 await new Promise ( resolve => setTimeout ( resolve , 50 ) ) ;
301307 await toHandle . drop ( fromHandle ) ;
302308 } ) ;
303309 response . appendResponseLine ( `Successfully dragged an element` ) ;
310+ appendNavigatedToUrl ( response , result ) ;
304311 if ( request . params . includeSnapshot ) {
305312 response . includeSnapshot ( ) ;
306313 }
@@ -332,17 +339,22 @@ export const fillForm = definePageTool({
332339 } ,
333340 handler : async ( request , response , context ) => {
334341 const page = request . page ;
342+ let lastResult : { navigatedToUrl ?: string } = { } ;
335343 for ( const element of request . params . elements ) {
336- await page . waitForEventsAfterAction ( async ( ) => {
344+ const result = await page . waitForEventsAfterAction ( async ( ) => {
337345 await fillFormElement (
338346 element . uid ,
339347 element . value ,
340348 context as McpContext ,
341349 page ,
342350 ) ;
343351 } ) ;
352+ if ( result . navigatedToUrl ) {
353+ lastResult = result ;
354+ }
344355 }
345356 response . appendResponseLine ( `Successfully filled out the form` ) ;
357+ appendNavigatedToUrl ( response , lastResult ) ;
346358 if ( request . params . includeSnapshot ) {
347359 response . includeSnapshot ( ) ;
348360 }
@@ -419,7 +431,7 @@ export const pressKey = definePageTool({
419431 const tokens = parseKey ( request . params . key ) ;
420432 const [ key , ...modifiers ] = tokens ;
421433
422- await page . waitForEventsAfterAction ( async ( ) => {
434+ const result = await page . waitForEventsAfterAction ( async ( ) => {
423435 for ( const modifier of modifiers ) {
424436 await page . pptrPage . keyboard . down ( modifier ) ;
425437 }
@@ -432,6 +444,7 @@ export const pressKey = definePageTool({
432444 response . appendResponseLine (
433445 `Successfully pressed key: ${ request . params . key } ` ,
434446 ) ;
447+ appendNavigatedToUrl ( response , result ) ;
435448 if ( request . params . includeSnapshot ) {
436449 response . includeSnapshot ( ) ;
437450 }
0 commit comments