-
Notifications
You must be signed in to change notification settings - Fork 31
add navigator clipboard, ClipboardItem #18
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
Conversation
|
This is great, thank you @keithamus for putting this together 🎉
|
|
theinterned
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super cool, just left my one drive-by question
164abf9 to
faa236c
Compare
faa236c to
f054df8
Compare
This comment was marked as spam.
This comment was marked as spam.
|
Tested today on Firefox and confirmed that this fixes the Copy Remote functionality in the blob page for Firefox, see details on https://github.com/github/repos/issues/1073#issuecomment-1226971804. |
JoseInTheArena
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm 🚀
This implements
navigator.clipboard.writeandnavigator.clipboard.read, which both work withClipboardItems. It also adds a re-implementation ofClipboardItemwhich supports Promises, adhering to the spec.write, per the spec takes an array ofClipboardItems and writes to the clipboard. We're limited in what we can do here, so we extract thetext/plaincontent of the first one and callwriteText. This is a pretty reasonable default behaviour.read, per the spec should return an array ofClipboardItems representing the user's current clipboard. We're limited what we can do here, so we callreadTextand convert it into aClipboardItemwith justtext/plain.ClipboardItemhas apresentationStyleattribute (defaulting to'unspecified'unless it's passed as an option), andgetType()always returnsBlobs. In Chrome's buggy implementation,getType('text/plain')will return a String. We've accounted for both possibilities innavigator.clipboard.writejust in case the polyfill isn't applied (e.g. Chrome adds promises but keeps their buggygetType()behaviour).This means
await navigator.clipboard.write(await navigator.clipboard.read())should be a no-op (as long as the user only has plain-text data in their clipboard) which feels like a sensible thing to do.Customer Support Data
Here are some tables representing the % of browsers we see that support (or don't support) these APIs.
Clipboard Write
(Note: "Other" browsers make up 0.408%)