Skip to content

[Clipboard] Add support for Clipboard Web API #17593

@EdricChan03

Description

@EdricChan03

Feature Description

Currently, the clipboard code from the CDK uses a <textarea> element and calls document.execCommand('copy') on the selected text in the <textarea>. However, this may be troublesome especially if there's a long amount of text to be copied.

What I'm suggesting is to use the Clipboard.writeText method from the Clipboard API.

Here's a description of the Clipboard API:

The Clipboard API provides the ability to respond to clipboard commands (cut, copy, and paste) as well as to asynchronously read from and write to the system clipboard. Access to the contents of the clipboard is gated behind the Permissions API; without user permission, reading or altering the clipboard contents is not permitted.

This API is designed to supersede accessing the clipboard using document.execCommand(). - from MDN docs for the Clipboard API

Currently, the Clipboard API is supported in the following browsers:

Screenshot of supported browsers table from Clipboard API document on MDN

However, according to the MDN docs for "Clipboard availability", it mentions that:

The asynchronous clipboard API is a relatively recent addition, and the process of implementing it in browsers is not yet complete. Due to both potential security concerns and technical complexities, the process of integrating this API is happening gradually in most browsers.

Use Case

This would add another method of copying text instead of the current approach.

Metadata

Metadata

Assignees

Labels

P5The team acknowledges the request but does not plan to address it, it remains open for discussionarea: cdk/clipboardfeatureThis issue represents a new feature or feature request rather than a bug or bug fixneeds: discussionFurther discussion with the team is needed before proceeding

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions