Microsoft/vscode

Clipboard APIs do not work inside iframes in webviews

Open

#182.642 aberto em 16 de mai. de 2023

Ver no GitHub
 (1 comment) (24 reactions) (1 assignee)TypeScript (10.221 forks)batch import
bughelp wantedwebview

Métricas do repositório

Stars
 (74.848 stars)
Métricas de merge de PR
 (Mesclagem média 11h 43m) (1.000 fundiu PRs em 30d)

Description

Create a webview that has an iframe with allow="clipboard-write":

<iframe src="http://127.0.0.1:8000/"  allow="clipboard-write" width="100%" height="600" />

In the hosted page, try to use the clipboard APIs:

<button onclick="window.navigator.clipboard.writeText('inner');">Copy "inner" to clipboard</button>

When clicking the button, the operation will fail and the developer tools will report:

Uncaught (in promise) DOMException: Write permission denied.

I've tried numerous combinations of things in the allow attribute (such as clipboard and clipboard-write http://127.0.0.1:8000/), but nothing seems to fix this. I presume the iframe being another origin is complicating things.

However, outside of VS Code this works fine. I made iframes nested three-deep that cross origins, and as long as I have allow="clipboard-write" then all of the nested frames are able to call this API successfully.

This might be related to https://github.com/microsoft/vscode/issues/129178 (which is that the system-level Cmd+C shortcut does not work), but I'm not sure these two things should be the same (one is the system copying something, and the other is JavaScript access to the clipboard API) so am raising a separate issue.

Guia do colaborador