Skip to content

Commit e53bbad

Browse files
committed
fix(extension): use _forwardToExtension for Target.closeTarget
Reuse _forwardToExtension helper for consistent tabId resolution instead of manually extracting tabId. Also await the close to ensure the tab is actually closed before emitting the detach event.
1 parent 511b5f2 commit e53bbad

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,9 @@ 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;
347+
// Forward the close to the extension so the real browser tab is closed.
348+
await this._forwardToExtension(method, params, tabSessionId);
348349
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(() => {});
352350
this._sendToPlaywright({
353351
method: 'Target.detachedFromTarget',
354352
params: { sessionId: tabSessionId, targetId },

0 commit comments

Comments
 (0)