Permissions-Policy: clipboard-write directive
The HTTP Permissions-Policy header clipboard-write directive controls whether the current document is allowed to write data to the system clipboard using the write() and writeText() methods of the Clipboard API.
Specifically, where a defined policy blocks usage of this feature, write() and writeText() calls will reject with a NotAllowedError DOMException.
Syntax
Permissions-Policy: clipboard-write=<allowlist>;
<allowlist>-
A list of origins for which permission is granted to use the feature. See
Permissions-Policy> Syntax for more details.
Default policy
The default allowlist for clipboard-write is self.
Examples
>Basic usage
SecureCorp Inc. wants to disallow clipboard-write within all cross-origin iframes except those whose origin is https://example.com.
It can do so by delivering the following HTTP response header to define a Permissions Policy:
Permissions-Policy: clipboard-write=(self "https://example.com")
SecureCorp Inc. must also include an allow attribute on each <iframe> element hosting content from https://example.com that needs to write to the clipboard:
<iframe src="https://example.com/copy-widget" allow="clipboard-write"></iframe>
With this header and allow attribute:
- The top-level document and same-origin iframes can write to the clipboard.
Same-origin iframes don't need the
allowattribute. - iframes hosting content from
https://example.comcan write to the clipboard. Without theallowattribute they couldn't, becausehttps://example.comisn't in the default allowlist (self). - iframes hosting content from any other origin can't write to the clipboard, even if they set
allow="clipboard-write", because the header's allowlist doesn't include their origin.
See Default allowlists and Inheritance of policies for embedded content in the Permissions Policy guide for more information.
Using the default policy
If no Permissions-Policy header sets an allowlist for clipboard-write, the default allowlist self applies.
This enables the feature in the top-level document and in same-origin iframes. The feature can also be used in cross-origin iframes if they have the allow attribute set:
<iframe src="https://other.com/share-widget" allow="clipboard-write"></iframe>
Specifications
This feature is not part of any specification.