api: add Frame.page() getter (#3392)
This commit is contained in:
parent
3a6b5cab42
commit
a574fa6edb
|
|
@ -2092,6 +2092,7 @@ console.log(text);
|
||||||
- [frame.innerText(selector[, options])](#frameinnertextselector-options)
|
- [frame.innerText(selector[, options])](#frameinnertextselector-options)
|
||||||
- [frame.isDetached()](#frameisdetached)
|
- [frame.isDetached()](#frameisdetached)
|
||||||
- [frame.name()](#framename)
|
- [frame.name()](#framename)
|
||||||
|
- [frame.page()](#framepage)
|
||||||
- [frame.parentFrame()](#frameparentframe)
|
- [frame.parentFrame()](#frameparentframe)
|
||||||
- [frame.press(selector, key[, options])](#framepressselector-key-options)
|
- [frame.press(selector, key[, options])](#framepressselector-key-options)
|
||||||
- [frame.selectOption(selector, values[, options])](#frameselectoptionselector-values-options)
|
- [frame.selectOption(selector, values[, options])](#frameselectoptionselector-values-options)
|
||||||
|
|
@ -2458,6 +2459,11 @@ If the name is empty, returns the id attribute instead.
|
||||||
|
|
||||||
> **NOTE** This value is calculated once when the frame is created, and will not update if the attribute is changed later.
|
> **NOTE** This value is calculated once when the frame is created, and will not update if the attribute is changed later.
|
||||||
|
|
||||||
|
#### frame.page()
|
||||||
|
- returns: <[Page]>
|
||||||
|
|
||||||
|
Returns the page containing this frame.
|
||||||
|
|
||||||
#### frame.parentFrame()
|
#### frame.parentFrame()
|
||||||
- returns: <[null]|[Frame]> Parent frame, if any. Detached frames and main frames return `null`.
|
- returns: <[null]|[Frame]> Parent frame, if any. Detached frames and main frames return `null`.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -374,6 +374,10 @@ export class Frame {
|
||||||
this._parentFrame._childFrames.add(this);
|
this._parentFrame._childFrames.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
page(): Page {
|
||||||
|
return this._page;
|
||||||
|
}
|
||||||
|
|
||||||
private _apiName(method: string) {
|
private _apiName(method: string) {
|
||||||
const subject = this._page._callingPageAPI ? 'page' : 'frame';
|
const subject = this._page._callingPageAPI ? 'page' : 'frame';
|
||||||
return `${subject}.${method}`;
|
return `${subject}.${method}`;
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,10 @@ export class Frame extends ChannelOwner<FrameChannel, FrameInitializer> {
|
||||||
return this._page!._isPageCall ? 'page.' + method : 'frame.' + method;
|
return this._page!._isPageCall ? 'page.' + method : 'frame.' + method;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
page(): Page {
|
||||||
|
return this._page!;
|
||||||
|
}
|
||||||
|
|
||||||
async goto(url: string, options: FrameGotoOptions = {}): Promise<network.Response | null> {
|
async goto(url: string, options: FrameGotoOptions = {}): Promise<network.Response | null> {
|
||||||
return this._wrapApiCall(this._apiName('goto'), async () => {
|
return this._wrapApiCall(this._apiName('goto'), async () => {
|
||||||
const waitUntil = verifyLoadState('waitUntil', options.waitUntil === undefined ? 'load' : options.waitUntil);
|
const waitUntil = verifyLoadState('waitUntil', options.waitUntil === undefined ? 'load' : options.waitUntil);
|
||||||
|
|
|
||||||
|
|
@ -189,3 +189,9 @@ it.fail(FFOX)('should refuse to display x-frame-options:deny iframe', async({pag
|
||||||
await page.setContent(`<iframe src="${server.CROSS_PROCESS_PREFIX}/x-frame-options-deny.html"></iframe>`);
|
await page.setContent(`<iframe src="${server.CROSS_PROCESS_PREFIX}/x-frame-options-deny.html"></iframe>`);
|
||||||
expect(await refusalText).toMatch(/Refused to display 'http.*\/x-frame-options-deny\.html' in a frame because it set 'X-Frame-Options' to 'deny'./i)
|
expect(await refusalText).toMatch(/Refused to display 'http.*\/x-frame-options-deny\.html' in a frame because it set 'X-Frame-Options' to 'deny'./i)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return frame.page()', async({page, server}) => {
|
||||||
|
await page.goto(server.PREFIX + '/frames/one-frame.html');
|
||||||
|
expect(page.mainFrame().page()).toBe(page);
|
||||||
|
expect(page.mainFrame().childFrames()[0].page()).toBe(page);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue