Skip to content

Commit b76547e

Browse files
committed
fix(extension): include targetId in detach event and forward close to extension
- Add targetId to synthetic Target.detachedFromTarget so Playwright's CRBrowser._onDetachedFromTarget can look up the page correctly - Forward Target.closeTarget to the extension so the actual browser tab is removed, keeping browser UI in sync with Playwright state
1 parent 421d507 commit b76547e

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

packages/playwright-core/src/tools/mcp/cdpRelay.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,14 @@ export class CDPRelayServer {
344344
const targetId = params?.targetId;
345345
const tabSessionId = this._findSessionByTargetId(targetId);
346346
if (tabSessionId) {
347+
const tabId = this._tabSessions.get(tabSessionId)!.tabId;
347348
this._removeTabSession(tabSessionId);
349+
// Forward the close to the extension so the actual browser tab is removed.
350+
if (tabId !== undefined)
351+
this._extensionConnection?.send('forwardCDPCommand', { tabId, method: 'Target.closeTarget', params }).catch(() => {});
348352
this._sendToPlaywright({
349353
method: 'Target.detachedFromTarget',
350-
params: { sessionId: tabSessionId },
354+
params: { sessionId: tabSessionId, targetId },
351355
});
352356
}
353357
return { success: true };

0 commit comments

Comments
 (0)