Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update clipboard API docs to better represent ClipboardItem with string item data #37677

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

chrisdavidmills
Copy link
Contributor

@chrisdavidmills chrisdavidmills commented Jan 16, 2025

Description

Chrome 133 now supports using item data of type string or a promise that resolves to a string when constructing a ClipboardItem object. Previously, Chrome only supported item data of type Blob, or a promise that resolves to a Blob, but this change brings it up to full standards support and parity with Firefox and Safari.

This PR mostly makes small changes to multiple pages to improve grammar and make sure ClipboardItem with string data is represented as a valid possibility.

I have also added a small example to the ClipboardItem landing page to show the simple case for text, where you don't need to use a Blob.

Motivation

Additional details

See https://chromestatus.com/feature/4926138582040576 for the data source.

The example I used for testing can be found at https://clipboard-api-string-test.glitch.me/.

Related issues and pull requests

BCD: mdn/browser-compat-data#25673

@chrisdavidmills chrisdavidmills requested a review from a team as a code owner January 16, 2025 15:49
@chrisdavidmills chrisdavidmills requested review from sideshowbarker and removed request for a team January 16, 2025 15:49
@github-actions github-actions bot added Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed labels Jan 16, 2025
@chrisdavidmills chrisdavidmills changed the title Update clipboard API docs to better represent ClipboardItem with stri… Update clipboard API docs to better represent ClipboardItem with string item data Jan 16, 2025
Copy link
Contributor

@tomayac tomayac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor suggestions, otherwise LGTM.

files/en-us/web/api/clipboard/write/index.md Outdated Show resolved Hide resolved
files/en-us/web/api/clipboard/write/index.md Outdated Show resolved Hide resolved
@@ -34,8 +34,7 @@ A {{jsxref("Promise")}} that resolves with a {{domxref("Blob")}} object.

## Examples

In the following example, we're returning all items on the clipboard via the {{domxref("clipboard.read()")}} method.
Then utilizing the {{domxref("ClipboardItem.types")}} property to set the `getType()` argument and return the corresponding blob object.
In the following example, we're returning all items on the clipboard via the {{domxref("clipboard.read()")}} method, then using the {{domxref("ClipboardItem.types")}} property to set the `getType()` argument and return the corresponding `Blob` object.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In the following example, we're returning all items on the clipboard via the {{domxref("clipboard.read()")}} method, then using the {{domxref("ClipboardItem.types")}} property to set the `getType()` argument and return the corresponding `Blob` object.
In the following example, we're returning all items on the clipboard via the {{domxref("clipboard.read()")}} method, then using the {{domxref("ClipboardItem.types")}} property to set the `getType()` argument, and return the corresponding `Blob` object.

Copy link
Contributor Author

@chrisdavidmills chrisdavidmills Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this one in a slightly different way:

In the following example, we're returning all items on the clipboard via the {{domxref("clipboard.read()")}} method. For each one, we pass the {{domxref("ClipboardItem.types")}} property to the getType() method, which returns the corresponding Blob object.

### Writing to the clipboard
### Writing text to the clipboard

In this example we first define two constants, which respectively contain references to a {{htmlelement("p")}} element containing some text, and a {{htmlelement("button")}}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In this example we first define two constants, which respectively contain references to a {{htmlelement("p")}} element containing some text, and a {{htmlelement("button")}}.
In this example, we first define two constants, which respectively contain references to a {{htmlelement("p")}} element containing some text, and a {{htmlelement("button")}} element.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this one like so:

In this example we first define two constants containing references to a {{htmlelement("p")}} element containing some text and a {{htmlelement("button")}} element.

files/en-us/web/api/clipboarditem/index.md Outdated Show resolved Hide resolved
@chrisdavidmills
Copy link
Contributor Author

Just some minor suggestions, otherwise LGTM.

Yay, thanks for the technical review, @tomayac!

@sideshowbarker sideshowbarker removed their request for review January 18, 2025 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants