@@ -90,12 +90,12 @@ function formatScriptExecutionError(
9090 ? [
9191 `1. Verify element exists: bdg dom query "${ selector } "` ,
9292 '2. Check element is visible and not disabled' ,
93- `3. Try direct eval: bdg dom eval "document.querySelector('${ escapeSelectorForJS ( selector ) } ').value = 'your-value'"` ,
93+ `3. Try direct eval: bdg eval "document.querySelector('${ escapeSelectorForJS ( selector ) } ').value = 'your-value'"` ,
9494 ]
9595 : [
9696 `1. Verify element exists: bdg dom query "${ selector } "` ,
9797 '2. Check element is visible and clickable' ,
98- `3. Try direct eval: bdg dom eval "document.querySelector('${ escapeSelectorForJS ( selector ) } ').click()"` ,
98+ `3. Try direct eval: bdg eval "document.querySelector('${ escapeSelectorForJS ( selector ) } ').click()"` ,
9999 ] ;
100100
101101 lines . push ( '' ) ;
@@ -133,6 +133,7 @@ export async function fillElement(
133133 const scriptOptions = {
134134 blur : options . blur ?? true ,
135135 index : options . index ,
136+ frame : options . frame ,
136137 } ;
137138
138139 const expression = `(${ REACT_FILL_SCRIPT } )('${ escapeSelectorForJS ( selector ) } ', '${ escapeValueForJS ( value ) } ', ${ JSON . stringify ( scriptOptions ) } )` ;
@@ -201,10 +202,11 @@ export async function fillElement(
201202export async function clickElement (
202203 cdp : CDPConnection ,
203204 selector : string ,
204- options : { index ?: number } = { }
205+ options : { index ?: number ; frame ?: string } = { }
205206) : Promise < ClickResult > {
206207 const indexArg = options . index ?? 'null' ;
207- const expression = `(${ CLICK_ELEMENT_SCRIPT } )('${ escapeSelectorForJS ( selector ) } ', ${ indexArg } )` ;
208+ const frameArg = options . frame ? `'${ escapeSelectorForJS ( options . frame ) } '` : 'null' ;
209+ const expression = `(${ CLICK_ELEMENT_SCRIPT } )('${ escapeSelectorForJS ( selector ) } ', ${ indexArg } , ${ frameArg } )` ;
208210
209211 try {
210212 const response = await cdp . send ( 'Runtime.evaluate' , {
@@ -346,6 +348,8 @@ export interface PressKeyOptions {
346348 index ?: number ;
347349 /** Number of times to press the key (default: 1) */
348350 times ?: number ;
351+ /** CSS selector for iframe to query within */
352+ frame ?: string ;
349353 /** Comma-separated modifier keys (shift, ctrl, alt, meta) */
350354 modifiers ?: string ;
351355}
@@ -370,9 +374,9 @@ export interface PressKeyResult {
370374 * @returns Object with success status and element info
371375 */
372376const FOCUS_ELEMENT_SCRIPT = `
373- (function(selector) {
377+ (function(selector, frameSelector ) {
374378${ QUERY_ELEMENTS_HELPER }
375- const elements = __bdgQueryElements(selector);
379+ const elements = __bdgQueryElements(selector, frameSelector || null );
376380 if (elements.length === 0) {
377381 return { success: false, error: 'No nodes found matching selector: ' + selector };
378382 }
@@ -429,7 +433,8 @@ export async function pressKeyElement(
429433
430434 const times = options . times ?? 1 ;
431435 const modifierFlags = parseModifiers ( options . modifiers ) ;
432- const focusExpression = `(${ FOCUS_ELEMENT_SCRIPT } )('${ escapeSelectorForJS ( selector ) } ')` ;
436+ const frameArg = options . frame ? `'${ escapeSelectorForJS ( options . frame ) } '` : 'null' ;
437+ const focusExpression = `(${ FOCUS_ELEMENT_SCRIPT } )('${ escapeSelectorForJS ( selector ) } ', ${ frameArg } )` ;
433438
434439 try {
435440 const focusResponse = await cdp . send ( 'Runtime.evaluate' , {
@@ -597,6 +602,8 @@ export interface ScrollOptions {
597602 bottom ?: boolean ;
598603 /** Element index if selector matches multiple (0-based) */
599604 index ?: number ;
605+ /** CSS selector for iframe to query within */
606+ frame ?: string ;
600607}
601608
602609/**
@@ -631,9 +638,9 @@ export interface ScrollResult {
631638 * Script to scroll an element into view.
632639 */
633640const SCROLL_TO_ELEMENT_SCRIPT = `
634- (function(selector) {
641+ (function(selector, frameSelector ) {
635642${ QUERY_ELEMENTS_HELPER }
636- const elements = __bdgQueryElements(selector);
643+ const elements = __bdgQueryElements(selector, frameSelector || null );
637644 if (elements.length === 0) {
638645 return { success: false, error: 'No nodes found matching selector: ' + selector };
639646 }
@@ -747,7 +754,8 @@ export async function scrollPage(
747754) : Promise < ScrollResult > {
748755 try {
749756 if ( selector ) {
750- const expression = `(${ SCROLL_TO_ELEMENT_SCRIPT } )('${ escapeSelectorForJS ( selector ) } ')` ;
757+ const frameArg = options . frame ? `'${ escapeSelectorForJS ( options . frame ) } '` : 'null' ;
758+ const expression = `(${ SCROLL_TO_ELEMENT_SCRIPT } )('${ escapeSelectorForJS ( selector ) } ', ${ frameArg } )` ;
751759
752760 const response = await cdp . send ( 'Runtime.evaluate' , {
753761 expression,
0 commit comments