File tree 2 files changed +21
-1
lines changed
packages/puppeteer-core/src/api
2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -424,7 +424,9 @@ export abstract class Frame extends EventEmitter<FrameEvents> {
424
424
for await ( using iframe of transposeIterableHandle ( list ) ) {
425
425
const frame = await iframe . contentFrame ( ) ;
426
426
if ( frame ?. _id === this . _id ) {
427
- return ( iframe as HandleFor < HTMLIFrameElement > ) . move ( ) ;
427
+ return ( await parentFrame
428
+ . mainRealm ( )
429
+ . adoptHandle ( iframe ) ) as HandleFor < HTMLIFrameElement > ;
428
430
}
429
431
}
430
432
return null ;
Original file line number Diff line number Diff line change @@ -341,5 +341,23 @@ describe('Frame specs', function () {
341
341
} ) ,
342
342
) . toBe ( 'iframe' ) ;
343
343
} ) ;
344
+
345
+ it ( 'should return ElementHandle in the correct world' , async ( ) => {
346
+ const { page, server} = await getTestState ( ) ;
347
+ await attachFrame ( page , 'theFrameId' , server . EMPTY_PAGE ) ;
348
+ await page . evaluate ( ( ) => {
349
+ // @ts -expect-error different page context
350
+ globalThis [ 'isMainWorld' ] = true ;
351
+ } , server . EMPTY_PAGE ) ;
352
+ expect ( page . frames ( ) ) . toHaveLength ( 2 ) ;
353
+ using frame1 = await page . frames ( ) [ 1 ] ! . frameElement ( ) ;
354
+ assert ( frame1 ) ;
355
+ assert (
356
+ await frame1 . evaluate ( ( ) => {
357
+ // @ts -expect-error different page context
358
+ return globalThis [ 'isMainWorld' ] ;
359
+ } ) ,
360
+ ) ;
361
+ } ) ;
344
362
} ) ;
345
363
} ) ;
You can’t perform that action at this time.
0 commit comments