@@ -30,6 +30,7 @@ import {WaitForHelper} from './WaitForHelper.js';
3030export interface TextSnapshotNode extends SerializedAXNode {
3131 id : string ;
3232 children : TextSnapshotNode [ ] ;
33+ value ?: string | number ;
3334}
3435
3536export interface TextSnapshot {
@@ -326,19 +327,36 @@ export class McpContext implements Context {
326327 // will be used for the tree serialization and mapping ids back to nodes.
327328 let idCounter = 0 ;
328329 const idToNode = new Map < string , TextSnapshotNode > ( ) ;
329- const assignIds = ( node : SerializedAXNode ) : TextSnapshotNode => {
330+ const assignIds = async (
331+ node : SerializedAXNode ,
332+ ) : Promise < TextSnapshotNode > => {
330333 const nodeWithId : TextSnapshotNode = {
331334 ...node ,
332335 id : `${ snapshotId } _${ idCounter ++ } ` ,
333- children : node . children
334- ? node . children . map ( child => assignIds ( child ) )
335- : [ ] ,
336+ children : [ ] ,
336337 } ;
338+
339+ // The AXNode for an option doesn't contain its value, so add it from the element.
340+ if ( node . role === 'option' ) {
341+ const handle = await node . elementHandle ( ) ;
342+ if ( handle ) {
343+ const valueHandle = await handle . getProperty ( 'value' ) ;
344+ const optionValue = await valueHandle . jsonValue ( ) ;
345+ if ( optionValue ) {
346+ nodeWithId . value = optionValue . toString ( ) ;
347+ }
348+ }
349+ }
350+
351+ nodeWithId . children = node . children
352+ ? await Promise . all ( node . children . map ( child => assignIds ( child ) ) )
353+ : [ ] ;
354+
337355 idToNode . set ( nodeWithId . id , nodeWithId ) ;
338356 return nodeWithId ;
339357 } ;
340358
341- const rootNodeWithId = assignIds ( rootNode ) ;
359+ const rootNodeWithId = await assignIds ( rootNode ) ;
342360 this . #textSnapshot = {
343361 root : rootNodeWithId ,
344362 snapshotId : String ( snapshotId ) ,
0 commit comments