mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-05 19:04:43 +03:00
fix(frameElement): should work for frames inside closed shadow root (#17055)
This commit is contained in:
parent
85698f51c7
commit
b734f36f8b
@ -571,17 +571,14 @@ export class FFPage implements PageDelegate {
|
||||
const parent = frame.parentFrame();
|
||||
if (!parent)
|
||||
throw new Error('Frame has been detached.');
|
||||
const info = this._page.parseSelector('frame,iframe');
|
||||
const handles = await this._page.selectors._queryAll(parent, info);
|
||||
const items = await Promise.all(handles.map(async handle => {
|
||||
const frame = await handle.contentFrame().catch(e => null);
|
||||
return { handle, frame };
|
||||
}));
|
||||
const result = items.find(item => item.frame === frame);
|
||||
items.map(item => item === result ? Promise.resolve() : item.handle.dispose());
|
||||
if (!result)
|
||||
const context = await parent._mainContext();
|
||||
const result = await this._session.send('Page.adoptNode', {
|
||||
frameId: frame._id,
|
||||
executionContextId: ((context as any)[contextDelegateSymbol] as FFExecutionContext)._executionContextId
|
||||
});
|
||||
if (!result.remoteObject)
|
||||
throw new Error('Frame has been detached.');
|
||||
return result.handle;
|
||||
return context.createHandle(result.remoteObject) as dom.ElementHandle;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -988,17 +988,14 @@ export class WKPage implements PageDelegate {
|
||||
const parent = frame.parentFrame();
|
||||
if (!parent)
|
||||
throw new Error('Frame has been detached.');
|
||||
const info = this._page.parseSelector('frame,iframe');
|
||||
const handles = await this._page.selectors._queryAll(parent, info);
|
||||
const items = await Promise.all(handles.map(async handle => {
|
||||
const frame = await handle.contentFrame().catch(e => null);
|
||||
return { handle, frame };
|
||||
}));
|
||||
const result = items.find(item => item.frame === frame);
|
||||
items.map(item => item === result ? Promise.resolve() : item.handle.dispose());
|
||||
if (!result)
|
||||
const context = await parent._mainContext();
|
||||
const result = await this._session.send('DOM.resolveNode', {
|
||||
frameId: frame._id,
|
||||
executionContextId: ((context as any)[contextDelegateSymbol] as WKExecutionContext)._contextId
|
||||
});
|
||||
if (!result || result.object.subtype === 'null')
|
||||
throw new Error('Frame has been detached.');
|
||||
return result.handle;
|
||||
return context.createHandle(result.object) as dom.ElementHandle;
|
||||
}
|
||||
|
||||
_onRequestWillBeSent(session: WKSession, event: Protocol.Network.requestWillBeSentPayload) {
|
||||
|
@ -55,3 +55,23 @@ it('should throw when detached', async ({ page, server }) => {
|
||||
const error = await frame1.frameElement().catch(e => e);
|
||||
expect(error.message).toContain('Frame has been detached.');
|
||||
});
|
||||
|
||||
it('should work inside closed shadow root', async ({ page, server, browserName }) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
await page.setContent(`
|
||||
<div id=framecontainer>
|
||||
</div>
|
||||
<script>
|
||||
const iframe = document.createElement('iframe');
|
||||
iframe.setAttribute('name', 'myframe');
|
||||
iframe.setAttribute('srcdoc', 'find me');
|
||||
const div = document.getElementById('framecontainer');
|
||||
const host = div.attachShadow({ mode: 'closed' });
|
||||
host.appendChild(iframe);
|
||||
</script>
|
||||
`);
|
||||
|
||||
const frame = page.frame({ name: 'myframe' });
|
||||
const element = await frame.frameElement();
|
||||
expect(await element.getAttribute('name')).toBe('myframe');
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user