Skip to content

fix(vscode): enable clipboard in webview iframe#968

Closed
rushelex wants to merge 1 commit into
backnotprop:mainfrom
rushelex:fix/vscode-clipboard-864
Closed

fix(vscode): enable clipboard in webview iframe#968
rushelex wants to merge 1 commit into
backnotprop:mainfrom
rushelex:fix/vscode-clipboard-864

Conversation

@rushelex

Copy link
Copy Markdown
Contributor

Problem

Closes #864.

In the VS Code extension, copying text from the Plannotator tab and pasting into a comment both silently fail.

Root cause

PanelManager renders the Plannotator app inside an <iframe> within the VS Code webview (apps/vscode-extension/src/panel-manager.ts). A VS Code webview is itself a sandboxed iframe, so a nested iframe is gated by Permissions Policy. The iframe had no allow attribute, which blocks navigator.clipboard reads/writes and paste events in the embedded app.

The app relies on navigator.clipboard.writeText for every copy action (code blocks, tables, export, annotations, …) and on clipboardData for paste — all of these are blocked under the default permissions policy of a nested iframe.

Fix

Grant clipboard access to the iframe:

<iframe id="pn-frame" src="${url}" allow="clipboard-read; clipboard-write"></iframe>

Testing

  • Added a panel-manager.test.ts case asserting the iframe HTML carries allow="clipboard-read; clipboard-write".
  • bun test src/panel-manager.test.ts → 3 pass.
  • bun run build:vscode succeeds.

🤖 Generated with Claude Code

Copy and paste did not work inside the Plannotator VS Code panel because
the embedded iframe lacked an `allow` attribute. Nested iframes in a
VS Code webview are gated by Permissions Policy, so `navigator.clipboard`
reads/writes and paste events were blocked. Grant clipboard-read and
clipboard-write to the iframe.

Fixes backnotprop#864

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rushelex

Copy link
Copy Markdown
Contributor Author

Closing in favor of #970.

This PR added allow="clipboard-read; clipboard-write" to the iframe, but
testing in a live VS Code webview showed that's insufficient: the clipboard
failure is NotAllowedError: Document is not focused, not a Permissions
Policy block — the nested iframe document never holds focus, so the async
Clipboard API is rejected and native copy/paste events don't fire at all.

The real fix routes the clipboard through the extension host
(vscode.env.clipboard) and drives copy/paste off keydown. See #970,
which closes both #864 and #969.

@rushelex rushelex closed this Jun 25, 2026
@rushelex rushelex deleted the fix/vscode-clipboard-864 branch June 25, 2026 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Content is not pasted from the clipboard in the VS Code extension

1 participant