Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

async clipboard article does cover Chrome's use of Promise #9806

Closed
fergald opened this issue Mar 24, 2023 · 2 comments · Fixed by #9816
Closed

async clipboard article does cover Chrome's use of Promise #9806

fergald opened this issue Mar 24, 2023 · 2 comments · Fixed by #9816
Assignees
Labels
content update for issues that do not require new content (only for updates to existing content) P2 A normal priority task. This is the default for most issues.

Comments

@fergald
Copy link

fergald commented Mar 24, 2023

Describe the bug

Chrome now supports writiing a Promise to the clipboard. The current docs only mention that for WebKit (at the bottom of the section on "write" .

It seems like synchronously setting a promise is the better way to do async clipboard copy. By using an async event handler, you risk overwriting an entry in the clipboard that was set before your async handler completed.

E.g. if the async handler waits for some other async event (e.g. a network request) before setting the clipboard, the clipboard could have been updated already.

@fergald fergald added the P2 A normal priority task. This is the default for most issues. label Mar 24, 2023
@AaronForinton AaronForinton added the content update for issues that do not require new content (only for updates to existing content) label Mar 24, 2023
tomayac added a commit that referenced this issue Mar 27, 2023
Document promise option.
Fixes #9806.
@tomayac
Copy link
Member

tomayac commented Mar 27, 2023

@fergald Thanks, tackled in #9816. In practice, I found the requirement to know the MIME type of the item beforehand limiting in some cases. Example:

// This randomly returns an `image/gif` or an `image/png` image.
const imgURL = '/images/random/';
await navigator.clipboard.write([
  new ClipboardItem({
    // This will be wrong when the returned image is an `image/gif`.
    'image/png': fetch(imgURL).then(response => response.blob()),
  })
]);

tomayac added a commit that referenced this issue Mar 27, 2023
…he clipboard (#9816)

* Update index.md

Document promise option.
Fixes #9806.

* Update src/site/content/en/blog/async-clipboard/index.md

Co-authored-by: Rachel Andrew <[email protected]>

---------

Co-authored-by: Rachel Andrew <[email protected]>
@fergald
Copy link
Author

fergald commented Mar 27, 2023

Thanks. That's a good point about mime types. I'm looking at this just because of this proposal for lazy generation of data only when the paste occurs. If they're tweaking the API, there might be an opportunity to address that .

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
content update for issues that do not require new content (only for updates to existing content) P2 A normal priority task. This is the default for most issues.
Projects
None yet
3 participants