Skip to content

Commit

Permalink
fix(webdriver): frameElement() should return handles in the main world (
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN authored Nov 11, 2024
1 parent 1626553 commit 2fde1ce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/puppeteer-core/src/api/Frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,9 @@ export abstract class Frame extends EventEmitter<FrameEvents> {
for await (using iframe of transposeIterableHandle(list)) {
const frame = await iframe.contentFrame();
if (frame?._id === this._id) {
return (iframe as HandleFor<HTMLIFrameElement>).move();
return (await parentFrame
.mainRealm()
.adoptHandle(iframe)) as HandleFor<HTMLIFrameElement>;
}
}
return null;
Expand Down
18 changes: 18 additions & 0 deletions test/src/frame.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,5 +341,23 @@ describe('Frame specs', function () {
}),
).toBe('iframe');
});

it('should return ElementHandle in the correct world', async () => {
const {page, server} = await getTestState();
await attachFrame(page, 'theFrameId', server.EMPTY_PAGE);
await page.evaluate(() => {
// @ts-expect-error different page context
globalThis['isMainWorld'] = true;
}, server.EMPTY_PAGE);
expect(page.frames()).toHaveLength(2);
using frame1 = await page.frames()[1]!.frameElement();
assert(frame1);
assert(
await frame1.evaluate(() => {
// @ts-expect-error different page context
return globalThis['isMainWorld'];
}),
);
});
});
});

0 comments on commit 2fde1ce

Please sign in to comment.