Microsoft/vscode

Clipboard APIs do not work inside iframes in webviews

开放

#182,642 创建于 2023年5月16日

 (1 条评论) (24 个反应) (1 位负责人)TypeScript (39,847 个派生)batch import
bughelp wantedwebview

仓库指标

星标
 (184,936 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

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.

贡献者指南