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();
|
const parent = frame.parentFrame();
|
||||||
if (!parent)
|
if (!parent)
|
||||||
throw new Error('Frame has been detached.');
|
throw new Error('Frame has been detached.');
|
||||||
const info = this._page.parseSelector('frame,iframe');
|
const context = await parent._mainContext();
|
||||||
const handles = await this._page.selectors._queryAll(parent, info);
|
const result = await this._session.send('Page.adoptNode', {
|
||||||
const items = await Promise.all(handles.map(async handle => {
|
frameId: frame._id,
|
||||||
const frame = await handle.contentFrame().catch(e => null);
|
executionContextId: ((context as any)[contextDelegateSymbol] as FFExecutionContext)._executionContextId
|
||||||
return { handle, frame };
|
});
|
||||||
}));
|
if (!result.remoteObject)
|
||||||
const result = items.find(item => item.frame === frame);
|
|
||||||
items.map(item => item === result ? Promise.resolve() : item.handle.dispose());
|
|
||||||
if (!result)
|
|
||||||
throw new Error('Frame has been detached.');
|
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();
|
const parent = frame.parentFrame();
|
||||||
if (!parent)
|
if (!parent)
|
||||||
throw new Error('Frame has been detached.');
|
throw new Error('Frame has been detached.');
|
||||||
const info = this._page.parseSelector('frame,iframe');
|
const context = await parent._mainContext();
|
||||||
const handles = await this._page.selectors._queryAll(parent, info);
|
const result = await this._session.send('DOM.resolveNode', {
|
||||||
const items = await Promise.all(handles.map(async handle => {
|
frameId: frame._id,
|
||||||
const frame = await handle.contentFrame().catch(e => null);
|
executionContextId: ((context as any)[contextDelegateSymbol] as WKExecutionContext)._contextId
|
||||||
return { handle, frame };
|
});
|
||||||
}));
|
if (!result || result.object.subtype === 'null')
|
||||||
const result = items.find(item => item.frame === frame);
|
|
||||||
items.map(item => item === result ? Promise.resolve() : item.handle.dispose());
|
|
||||||
if (!result)
|
|
||||||
throw new Error('Frame has been detached.');
|
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) {
|
_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);
|
const error = await frame1.frameElement().catch(e => e);
|
||||||
expect(error.message).toContain('Frame has been detached.');
|
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 a new issue