mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(oopif): dispose child sessions when frame session is disposed (#13693)
This commit is contained in:
parent
5990eb6074
commit
801dbe0699
@ -386,6 +386,8 @@ class FrameSession {
|
|||||||
readonly _crPage: CRPage;
|
readonly _crPage: CRPage;
|
||||||
readonly _page: Page;
|
readonly _page: Page;
|
||||||
readonly _networkManager: CRNetworkManager;
|
readonly _networkManager: CRNetworkManager;
|
||||||
|
private readonly _parentSession: FrameSession | null;
|
||||||
|
private readonly _childSessions = new Set<FrameSession>();
|
||||||
private readonly _contextIdToContext = new Map<number, dom.FrameExecutionContext>();
|
private readonly _contextIdToContext = new Map<number, dom.FrameExecutionContext>();
|
||||||
private _eventListeners: RegisteredListener[] = [];
|
private _eventListeners: RegisteredListener[] = [];
|
||||||
readonly _targetId: string;
|
readonly _targetId: string;
|
||||||
@ -408,6 +410,9 @@ class FrameSession {
|
|||||||
this._page = crPage._page;
|
this._page = crPage._page;
|
||||||
this._targetId = targetId;
|
this._targetId = targetId;
|
||||||
this._networkManager = new CRNetworkManager(client, this._page, parentSession ? parentSession._networkManager : null);
|
this._networkManager = new CRNetworkManager(client, this._page, parentSession ? parentSession._networkManager : null);
|
||||||
|
this._parentSession = parentSession;
|
||||||
|
if (parentSession)
|
||||||
|
parentSession._childSessions.add(this);
|
||||||
this._firstNonInitialNavigationCommittedPromise = new Promise((f, r) => {
|
this._firstNonInitialNavigationCommittedPromise = new Promise((f, r) => {
|
||||||
this._firstNonInitialNavigationCommittedFulfill = f;
|
this._firstNonInitialNavigationCommittedFulfill = f;
|
||||||
this._firstNonInitialNavigationCommittedReject = r;
|
this._firstNonInitialNavigationCommittedReject = r;
|
||||||
@ -569,6 +574,10 @@ class FrameSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
|
for (const childSession of this._childSessions)
|
||||||
|
childSession.dispose();
|
||||||
|
if (this._parentSession)
|
||||||
|
this._parentSession._childSessions.delete(this);
|
||||||
eventsHelper.removeEventListeners(this._eventListeners);
|
eventsHelper.removeEventListeners(this._eventListeners);
|
||||||
this._networkManager.dispose();
|
this._networkManager.dispose();
|
||||||
this._crPage._sessions.delete(this._targetId);
|
this._crPage._sessions.delete(this._targetId);
|
||||||
|
10
tests/assets/inner-oopif.html
Normal file
10
tests/assets/inner-oopif.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<script>
|
||||||
|
window.addEventListener('DOMContentLoaded', () => {
|
||||||
|
const iframe = document.createElement('iframe');
|
||||||
|
const url = new URL(location.href);
|
||||||
|
url.hostname = '127.0.0.2';
|
||||||
|
url.pathname = '/one-style.html';
|
||||||
|
iframe.src = url.toString();
|
||||||
|
document.body.appendChild(iframe);
|
||||||
|
}, false);
|
||||||
|
</script>
|
14
tests/assets/outer-oopif.html
Normal file
14
tests/assets/outer-oopif.html
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<script>
|
||||||
|
window.addEventListener('DOMContentLoaded', () => {
|
||||||
|
const iframe = document.createElement('iframe');
|
||||||
|
const url = new URL(location.href);
|
||||||
|
url.hostname = '127.0.0.1';
|
||||||
|
url.pathname = '/inner-oopif.html';
|
||||||
|
iframe.src = url.toString();
|
||||||
|
document.body.appendChild(iframe);
|
||||||
|
setTimeout(() => {
|
||||||
|
url.hostname = '127.0.0.3'
|
||||||
|
iframe.src = url.toString();
|
||||||
|
}, 50);
|
||||||
|
}, false);
|
||||||
|
</script>
|
@ -94,6 +94,16 @@ it('should expose function', async ({ page, browser, server }) => {
|
|||||||
expect(result).toBe(36);
|
expect(result).toBe(36);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not hang in exposeBinding when nested oopifs navigate', async ({ page, browser, server }) => {
|
||||||
|
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/13637' });
|
||||||
|
await page.goto(server.PREFIX + '/outer-oopif.html');
|
||||||
|
await page.context().exposeBinding('mul', (source, a, b) => a * b);
|
||||||
|
const result = await page.evaluate(async function() {
|
||||||
|
return await window['mul'](9, 4);
|
||||||
|
});
|
||||||
|
expect(result).toBe(36);
|
||||||
|
});
|
||||||
|
|
||||||
it('should emulate media', async ({ page, browser, server }) => {
|
it('should emulate media', async ({ page, browser, server }) => {
|
||||||
await page.goto(server.PREFIX + '/dynamic-oopif.html');
|
await page.goto(server.PREFIX + '/dynamic-oopif.html');
|
||||||
expect(page.frames().length).toBe(2);
|
expect(page.frames().length).toBe(2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user