@@ -413,13 +413,10 @@ export class BidiPage implements PageDelegate {
413413
414414 async getContentFrame ( handle : dom . ElementHandle ) : Promise < frames . Frame | null > {
415415 const executionContext = toBidiExecutionContext ( handle . _context ) ;
416- const contentWindow = await executionContext . rawCallFunction ( 'e => e.contentWindow' , { handle : handle . _objectId } ) ;
417- if ( contentWindow . type === 'window' ) {
418- const frameId = contentWindow . value . context ;
419- const result = this . _page . _frameManager . frame ( frameId ) ;
420- return result ;
421- }
422- return null ;
416+ const frameId = await executionContext . contentFrameIdForFrame ( handle ) ;
417+ if ( ! frameId )
418+ return null ;
419+ return this . _page . _frameManager . frame ( frameId ) ;
423420 }
424421
425422 async getOwnerFrame ( handle : dom . ElementHandle ) : Promise < string | null > {
@@ -430,15 +427,8 @@ export class BidiPage implements PageDelegate {
430427 } ) ;
431428 if ( ! windowHandle )
432429 return null ;
433- if ( ! windowHandle . _objectId )
434- return null ;
435- const executionContext = toBidiExecutionContext ( windowHandle . _context as dom . FrameExecutionContext ) ;
436- const contentWindow = await executionContext . rawCallFunction ( 'e => e' , { handle : windowHandle . _objectId } ) ;
437- if ( contentWindow . type === 'window' ) {
438- const frameId = contentWindow . value . context ;
439- return frameId ;
440- }
441- return null ;
430+ const executionContext = toBidiExecutionContext ( handle . _context ) ;
431+ return executionContext . frameIdForWindowHandle ( windowHandle ) ;
442432 }
443433
444434 isElementHandle ( remoteObject : bidi . Script . RemoteValue ) : boolean {
@@ -535,29 +525,20 @@ export class BidiPage implements PageDelegate {
535525
536526 async setInputFilePaths ( handle : dom . ElementHandle < HTMLInputElement > , paths : string [ ] ) : Promise < void > {
537527 const fromContext = toBidiExecutionContext ( handle . _context ) ;
538- const shared = await fromContext . rawCallFunction ( 'x => x' , { handle : handle . _objectId } ) ;
539- // TODO: store sharedId in the handle.
540- if ( ! ( 'sharedId' in shared ) )
541- throw new Error ( 'Element is not a node' ) ;
542- const sharedId = shared . sharedId ! ;
543528 await this . _session . send ( 'input.setFiles' , {
544529 context : this . _session . sessionId ,
545- element : { sharedId } ,
530+ element : await fromContext . nodeIdForElementHandle ( handle ) ,
546531 files : paths ,
547532 } ) ;
548533 }
549534
550535 async adoptElementHandle < T extends Node > ( handle : dom . ElementHandle < T > , to : dom . FrameExecutionContext ) : Promise < dom . ElementHandle < T > > {
551536 const fromContext = toBidiExecutionContext ( handle . _context ) ;
552- const shared = await fromContext . rawCallFunction ( 'x => x' , { handle : handle . _objectId } ) ;
553- // TODO: store sharedId in the handle.
554- if ( ! ( 'sharedId' in shared ) )
555- throw new Error ( 'Element is not a node' ) ;
556- const sharedId = shared . sharedId ! ;
537+ const nodeId = await fromContext . nodeIdForElementHandle ( handle ) ;
557538 const executionContext = toBidiExecutionContext ( to ) ;
558- const result = await executionContext . rawCallFunction ( 'x => x' , { sharedId } ) ;
559- if ( 'handle' in result )
560- return to . createHandle ( { objectId : result . handle ! , ... result } ) as dom . ElementHandle < T > ;
539+ const objectId = await executionContext . remoteObjectForNodeId ( nodeId ) ;
540+ if ( objectId )
541+ return to . createHandle ( objectId ) as dom . ElementHandle < T > ;
561542 throw new Error ( 'Failed to adopt element handle.' ) ;
562543 }
563544
0 commit comments