Skip to content

Clipboard APIs do not work inside iframes in webviews #182642

Open

Description

@DanTup

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 #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.

Activity

  1. added
    webview
    bug
    help wanted
    on Jul 18, 2023
  2. nateshmbhat commented on Nov 9, 2024

    @nateshmbhat

    any update on this ? please check this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bughelp wantedwebview

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions