fix(agent-manager): route clipboard write through extension host (#8161)

The Copy Path context menu item called navigator.clipboard.writeText()
directly from the webview, which throws NotAllowedError when the
webview loses focus to the context menu. Route through vscode.env.clipboard
via the Host abstraction instead.
This commit is contained in:
Marius
2026-04-02 13:16:00 +02:00
committed by GitHub
parent 01be54fef7
commit a1a29f2a5e
6 changed files with 27 additions and 1 deletions
@@ -250,6 +250,10 @@ export class AgentManagerProvider implements Disposable {
this.openWorktreeDirectory(m.worktreeId)
return null
}
if (m.type === "agentManager.copyToClipboard") {
this.host.copyToClipboard(m.text)
return null
}
if (m.type === "previewImage") {
return msg
}
@@ -101,6 +101,9 @@ export interface Host {
/** Get the CLI server port (for webview CSP). */
serverPort(): number | undefined
/** Copy text to the system clipboard. */
copyToClipboard(text: string): void
/** Capture a telemetry event. */
capture(event: string, properties?: Record<string, unknown>): void
@@ -262,6 +262,11 @@ interface OpenWorktreeIn {
worktreeId: string
}
interface CopyToClipboardIn {
type: "agentManager.copyToClipboard"
text: string
}
interface ShowExistingLocalTerminalIn {
type: "agentManager.showExistingLocalTerminal"
}
@@ -462,6 +467,7 @@ export type AgentManagerInMessage =
| ShowTerminalIn
| ShowLocalTerminalIn
| OpenWorktreeIn
| CopyToClipboardIn
| ShowExistingLocalTerminalIn
| RequestRepoInfoIn
| CreateMultiVersionIn
@@ -152,6 +152,10 @@ export class VscodeHost implements Host {
return this.connectionService.getServerInfo()?.port
}
copyToClipboard(text: string): void {
void vscode.env.clipboard.writeText(text)
}
capture(event: string, properties?: Record<string, unknown>): void {
TelemetryProxy.capture(event as TelemetryEventName, properties)
}
@@ -2340,7 +2340,9 @@ const AgentManagerContent: Component = () => {
onCommitRename={() => commitRename(wt.id)}
onCancelRename={cancelRename}
onRemoveStale={() => confirmRemoveStaleWorktree(wt.id)}
onCopyPath={() => navigator.clipboard.writeText(wt.path)}
onCopyPath={() =>
vscode.postMessage({ type: "agentManager.copyToClipboard", text: wt.path })
}
onOpen={() =>
vscode.postMessage({ type: "agentManager.openWorktree", worktreeId: wt.id })
}
@@ -1772,6 +1772,12 @@ export interface OpenWorktreeRequest {
worktreeId: string
}
// Copy text to the system clipboard via the extension host
export interface CopyToClipboardRequest {
type: "agentManager.copyToClipboard"
text: string
}
// Show existing local terminal when switching to local context (no-op if none exists)
export interface ShowExistingLocalTerminalRequest {
type: "agentManager.showExistingLocalTerminal"
@@ -2096,6 +2102,7 @@ export type WebviewMessage =
| ShowTerminalRequest
| ShowLocalTerminalRequest
| OpenWorktreeRequest
| CopyToClipboardRequest
| ShowExistingLocalTerminalRequest
| AgentManagerOpenFileRequest
| CreateMultiVersionRequest