Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 22 additions & 1 deletion packages/playwright-core/src/tools/mcp/cdpRelayV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ export class ExtensionProtocolV2 implements ExtensionProtocolHandler {
const tabSession = await this._attachTab(tab.id);
return { result: { targetId: tabSession.targetInfo?.targetId } };
}
case 'Target.closeTarget': {
const targetId = params?.targetId;
const tabSession = this._findTabSessionByTargetId(targetId);
if (!tabSession)
return { result: { success: false } };
await this._sendCommand('chrome.tabs.remove', [tabSession.tabId]);
return { result: { success: true } };
}
case 'Target.getTargetInfo': {
if (!sessionId)
return { result: undefined };
Expand Down Expand Up @@ -180,7 +188,10 @@ export class ExtensionProtocolV2 implements ExtensionProtocolHandler {
this._tabSessions.delete(tabId);
this._sendToPlaywright({
method: 'Target.detachedFromTarget',
params: { sessionId: tabSession.sessionId },
params: {
sessionId: tabSession.sessionId,
targetId: tabSession.targetInfo?.targetId,
},
});
}

Expand All @@ -199,4 +210,14 @@ export class ExtensionProtocolV2 implements ExtensionProtocolHandler {
}
return undefined;
}

private _findTabSessionByTargetId(targetId: string | undefined): TabSession | undefined {
if (!targetId)
return undefined;
for (const session of this._tabSessions.values()) {
if (session.targetInfo?.targetId === targetId)
return session;
}
return undefined;
}
}
5 changes: 5 additions & 0 deletions packages/playwright-core/src/tools/mcp/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export type ExtensionCommandV2 = {
params: [createProperties: TabCreateProperties];
result: Tab;
};
// chrome.tabs.remove(tabIds)
'chrome.tabs.remove': {
params: [tabIds: number | number[]];
result: void;
};
// Playwright-specific: ask the user to pick a tab via the connect UI.
'extension.selectTab': {
params: [];
Expand Down
Loading