Skip to content

FF156 ClipBoard Async API - custom types - #45620

Open
hamishwillee wants to merge 8 commits into
mdn:mainfrom
hamishwillee:ff156_clipboard_async_api_custom
Open

hamishwillee wants to merge 8 commits into
mdn:mainfrom
hamishwillee:ff156_clipboard_async_api_custom

Conversation

@hamishwillee

@hamishwillee hamishwillee commented Sep 11, 2026 •

Copy link
Copy Markdown
Collaborator

FF156 adds support for the async Clipboard API to use web custom formats.

The API allows you to create a ClipboardItem that contains several representations of a copied object, such as version in HTML and Text, and push it to the system clipboard. Something else can read the clipboard and get back tha object - then choose the best format it understands.

The update allows you to (behind a pref) use other types than PNG, HTML, txt.

What this update does is

  • make the model above clear, because it wasn't - it referred too much to "arbitrary types" can didn't capture "different representations".
  • Add information about how to use various types and methods
  • Extend the API overview to cover the main use cases. One good example.

Related docs work can be tracked in #45430

@hamishwillee
hamishwillee requested a review from a team as a code owner September 11, 2026 07:07
@hamishwillee
hamishwillee requested review from sideshowbarker and removed request for a team September 11, 2026 07:07
@github-actions github-actions Bot added Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed labels Sep 11, 2026
@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

@pepelsbey
pepelsbey requested review from pepelsbey and removed request for sideshowbarker September 11, 2026 14:40

@pepelsbey pepelsbey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! Thank you 🙂

Just a few suggestions and a question.

Comment thread files/en-us/web/api/clipboard/index.md Outdated
Comment thread files/en-us/web/api/clipboard/index.md Outdated
Comment thread files/en-us/web/api/clipboarditem/clipboarditem/index.md Outdated
Comment thread files/en-us/web/api/clipboarditem/clipboarditem/index.md Outdated
@pepelsbey
pepelsbey requested a review from Josh-Cena September 11, 2026 15:16
@Josh-Cena

Copy link
Copy Markdown
Member

lmk if I can be of help but looks like the PR is already being reviewed.

@Josh-Cena
Josh-Cena removed their request for review September 11, 2026 21:49
Comment thread files/en-us/web/api/clipboarditem/clipboarditem/index.md Outdated
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@hamishwillee

Copy link
Copy Markdown
Collaborator Author

@pepelsbey I have fixed your suggestions. Ready for another look. I'll build my follow-on PR either on this or in this PR.

@pepelsbey pepelsbey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! A few more notes

Comment thread files/en-us/web/api/clipboard/read/index.md Outdated
Comment thread files/en-us/web/api/clipboard/read/index.md Outdated
Comment thread files/en-us/web/api/clipboard/read/index.md Outdated
Comment thread files/en-us/web/api/clipboarditem/clipboarditem/index.md Outdated
Comment thread files/en-us/web/api/clipboard/read/index.md Outdated
hamishwillee and others added 3 commits September 15, 2026 11:20
Co-authored-by: Vadim Makeev <hi@pepelsbey.dev>
Co-authored-by: Hamish Willee <hamishwillee@gmail.com>
@hamishwillee hamishwillee changed the title FF156 ClipBoard Async API - clarify types FF156 ClipBoard Async API - custom types Sep 15, 2026
@github-actions github-actions Bot added size/xl [PR only] >1000 LoC changed and removed size/m [PR only] 51-500 LoC changed labels Sep 15, 2026
@hamishwillee

Copy link
Copy Markdown
Collaborator Author

Thanks @pepelsbey . I fixed your issues and then extended this for the custom types. Everything needed for the docs on this project item in there now. Sorry, review now a bit bigger.

@hamishwillee

Copy link
Copy Markdown
Collaborator Author

@pepelsbey Can you have another check of this please

@pepelsbey pepelsbey left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Spotted a few more things to fix, nothing major. Otherwise, ready to go!

This lets a web app define its own clipboard format for data that has no standard representation, without colliding with the OS's native clipboard formats or another site's custom formats.

Custom formats are useful because they can preserve information a standard representation can't, for example structured metadata alongside a visual or text version of the same content.
An app that recognizes its own custom format can paste it with data loss for users who copy from it, while other apps still receive whichever standard representations you also provide.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
An app that recognizes its own custom format can paste it with data loss for users who copy from it, while other apps still receive whichever standard representations you also provide.
An app that recognizes its own custom format can paste it without data loss for users who copy from it, while other apps still receive whichever standard representations you also provide.

If I understood it correctly

Comment on lines +391 to +392
There is nothing special about the blob for the custom format: the only difference is the`web` prefix used for its key.
The `text/html` blob omits the `SKU` column stored in the custom format, and acts as a fall back when the content is pasted in apps and browsers that don't allow the format.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
There is nothing special about the blob for the custom format: the only difference is the`web` prefix used for its key.
The `text/html` blob omits the `SKU` column stored in the custom format, and acts as a fall back when the content is pasted in apps and browsers that don't allow the format.
There is nothing special about the blob for the custom format: the only difference is the `web` prefix used for its key.
The `text/html` blob omits the `SKU` column stored in the custom format, and acts as a fallback when the content is pasted in apps and browsers that don't support the format.


#### HTML

The HTML defines a {{htmlelement("p")}} element for the source text to be copied, {{htmlelement("button")}} elements to copy and paste the text, and an element into which the the text will be copied .

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
The HTML defines a {{htmlelement("p")}} element for the source text to be copied, {{htmlelement("button")}} elements to copy and paste the text, and an element into which the the text will be copied .
The HTML defines a {{htmlelement("p")}} element for the source text to be copied, {{htmlelement("button")}} elements to copy and paste the text, and an element into which the text will be copied.


document.querySelector("#paste_text").addEventListener("click", async () => {
try {
// Read the text from the clipboard write it to #target_text

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// Read the text from the clipboard write it to #target_text
// Read the text from the clipboard and write it to #target_text

As in the previous example, we create event handlers to copy the source element and paste to the target element.

The code that is run to copy the data is shown below.
Note how the code constructs the `ClipboardItem()` constructor with two representations of the same source data.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Note how the code constructs the `ClipboardItem()` constructor with two representations of the same source data.
Note how the code calls the `ClipboardItem()` constructor with two representations of the same source data.

“Constructs the constructor” is a bit awkward


### Reading and writing custom formats

This example demonstrates how applications can use custom formats to copy and paste a faithful representation of their data when the format is understood, and provide a graceful fall back where it is not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
This example demonstrates how applications can use custom formats to copy and paste a faithful representation of their data when the format is understood, and provide a graceful fall back where it is not.
This example demonstrates how applications can use custom formats to copy and paste a faithful representation of their data when the format is understood, and provide a graceful fallback where it is not.

This branch has not been deployed

No deployments
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/xl [PR only] >1000 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants