fix(oopif): dispose child sessions when frame session is disposed (#13693)

This commit is contained in:
Yury Semikhatsky 2022-04-21 18:32:56 -07:00 committed by GitHub
parent 5990eb6074
commit 801dbe0699
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 0 deletions

View File

@ -386,6 +386,8 @@ class FrameSession {
readonly _crPage: CRPage;
readonly _page: Page;
readonly _networkManager: CRNetworkManager;
private readonly _parentSession: FrameSession | null;
private readonly _childSessions = new Set<FrameSession>();
private readonly _contextIdToContext = new Map<number, dom.FrameExecutionContext>();
private _eventListeners: RegisteredListener[] = [];
readonly _targetId: string;
@ -408,6 +410,9 @@ class FrameSession {
this._page = crPage._page;
this._targetId = targetId;
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._firstNonInitialNavigationCommittedFulfill = f;
this._firstNonInitialNavigationCommittedReject = r;
@ -569,6 +574,10 @@ class FrameSession {
}
dispose() {
for (const childSession of this._childSessions)
childSession.dispose();
if (this._parentSession)
this._parentSession._childSessions.delete(this);
eventsHelper.removeEventListeners(this._eventListeners);
this._networkManager.dispose();
this._crPage._sessions.delete(this._targetId);

View 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>

View 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>

View File

@ -94,6 +94,16 @@ it('should expose function', async ({ page, browser, server }) => {
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 }) => {
await page.goto(server.PREFIX + '/dynamic-oopif.html');
expect(page.frames().length).toBe(2);