Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions packages/playwright-core/src/server/chromium/crPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,8 @@ class FrameSession {
this._firstNonInitialNavigationCommittedReject(new TargetClosedError(this._page.closeReason()));
for (const childSession of this._childSessions)
childSession.dispose();
for (const sessionId of this._workerSessions.keys())
this._removeWorkerSession(sessionId);
if (this._parentSession)
this._parentSession._childSessions.delete(this);
eventsHelper.removeEventListeners(this._eventListeners);
Expand Down Expand Up @@ -780,16 +782,21 @@ class FrameSession {
session.on('Runtime.exceptionThrown', exception => this._page.addPageError(exceptionToError(exception.exceptionDetails), stackTraceToLocation(exception.exceptionDetails.stackTrace)));
}

private _removeWorkerSession(sessionId: string): boolean {
const workerSession = this._workerSessions.get(sessionId);
if (!workerSession)
return false;
this._workerSessions.delete(sessionId);
this._crPage._networkManager.removeSession(workerSession);
workerSession.dispose();
this._page.removeWorker(sessionId);
return true;
}

_onDetachedFromTarget(event: Protocol.Target.detachedFromTargetPayload) {
// This might be a worker...
const workerSession = this._workerSessions.get(event.sessionId);
if (workerSession) {
this._workerSessions.delete(event.sessionId);
this._crPage._networkManager.removeSession(workerSession);
workerSession.dispose();
this._page.removeWorker(event.sessionId);
if (this._removeWorkerSession(event.sessionId))
return;
}

// ... or an oopif.
const childFrameSession = this._crPage._sessions.get(event.targetId!);
Expand Down
29 changes: 29 additions & 0 deletions tests/library/chromium/oopif.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import { contextTest as it, expect } from '../../config/browserTest';
import { attachFrame } from '../../config/utils';
import type { Frame, Browser } from '@playwright/test';

it.use({
Expand Down Expand Up @@ -43,6 +44,34 @@ it('should handle oopif detach', async function({ page, browser, server }) {
expect(detachedFrame).toBe(frame);
});

it('should remove workers of a detached oopif', async function({ page, browser, server }) {
await page.goto(server.EMPTY_PAGE);
const [worker] = await Promise.all([
page.waitForEvent('worker'),
attachFrame(page, 'frame1', server.CROSS_PROCESS_PREFIX + '/worker/worker.html'),
]);
await assertOOPIFCount(browser, 1);
expect(page.workers().length).toBe(1);
await Promise.all([
worker.waitForEvent('close'),
page.goto(server.PREFIX + '/title.html'),
]);
expect(page.workers().length).toBe(0);
});

it('should not hang in unrouteAll when oopif worker is gone', async function({ page, context, browser, server }) {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/42278' });
await context.route('**/*', route => route.continue());
await page.goto(server.EMPTY_PAGE);
await Promise.all([
page.waitForEvent('worker'),
attachFrame(page, 'frame1', server.CROSS_PROCESS_PREFIX + '/worker/worker.html'),
]);
await assertOOPIFCount(browser, 1);
await page.goto(server.CROSS_PROCESS_PREFIX + '/title.html');
await context.unrouteAll();
});

it('should handle remote -> local -> remote transitions', async function({ page, browser, server }) {
await page.goto(server.PREFIX + '/dynamic-oopif.html');
expect(page.frames().length).toBe(2);
Expand Down
Loading