Repository navigation
FF156 ClipBoard Async API - custom types - #45620
hamishwillee wants to merge 8 commits into
Conversation
Preview URLs (6 pages)(comment last updated: 2026-09-15 08:37:30) |
pepelsbey
left a comment
There was a problem hiding this comment.
Looks good! Thank you 🙂
Just a few suggestions and a question.
|
lmk if I can be of help but looks like the PR is already being reviewed. |
Co-authored-by: Vadim Makeev <hi@pepelsbey.dev>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
@pepelsbey I have fixed your suggestions. Ready for another look. I'll build my follow-on PR either on this or in this PR. |
Co-authored-by: Vadim Makeev <hi@pepelsbey.dev> Co-authored-by: Hamish Willee <hamishwillee@gmail.com>
|
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. |
|
@pepelsbey Can you have another check of this please |
| 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. |
There was a problem hiding this comment.
| 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
| 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 was a problem hiding this comment.
| 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 . |
There was a problem hiding this comment.
| 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 |
There was a problem hiding this comment.
| // 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. |
There was a problem hiding this comment.
| 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. |
There was a problem hiding this comment.
| 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. |
FF156 adds support for the async Clipboard API to use web custom formats.
The API allows you to create a
ClipboardItemthat 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
Related docs work can be tracked in #45430