Skip to content

Conversation

jkleinsc
Copy link
Member

@jkleinsc jkleinsc commented Aug 7, 2025

This RFC outlines a rearchitecturing of the clipboard module in Electron to improve alignment with the Clipboard API as specified by the W3C.

📄 Read rendered document

coauthored with @codebytere.

@jkleinsc jkleinsc requested a review from a team as a code owner August 7, 2025 19:20
@erickzhao erickzhao added the pending-review Waiting for reviewers to give feedback on the PR specifications label Aug 14, 2025
Comment on lines +87 to +89
* Custom MIME types e.g. `electron application/filepath` will be used to allow support of non-standard clipboard formats. This follows
the W3C proposal for supporting [Web Custom formats for Async Clipboard API](https://github.com/w3c/editing/blob/gh-pages/docs/clipboard-pickling/explainer.md#custom-formats).
The exception here is that instead of using the `web` prefix, we will use the `electron` prefix to prevent possible collisions with custom web formats.
Copy link

Choose a reason for hiding this comment

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

It's not clear to me whether electron can access arbitrary clipboard formats outside of a subset of whitelisted platform specific types. This uncertainty exists both for the current electron version (v37), as reported in electron/electron#39853 (comment), and in the proposed changes in this RFC.

AFAIU the W3C Async Clipboard API supports access to only a subset of possible formats as specified in well-known mime types and the clipboard API working draft which notes support of those with a web prefix (and this RFC adapts for an electron prefix).

Is access to arbitrary clipboard formats:

  • intended to work in the current electron clipboard API
  • intended to work in the proposed rearchitected clipboard API

This is a critical feature for my use case and I was encouraged to see this RFC in case there is any relation.

Copy link

Choose a reason for hiding this comment

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

With Electron 38 on Windows, clipboard.read and clipboard.readBuffer can access arbitrary clipboard formats. So I think we can conclude that prior to this re-architecture, the Electron intends to be able to read/write any clipboard format. And that this rearchitecture should preserve and refine this ability. By refine, I mean enhancements like making clipboard.availableFormats actually detect all available formats.

Copy link
Member Author

Choose a reason for hiding this comment

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

@dhimmel the intention would be that we wouldn’t lose any current functionality, so if a format is readable now it should be so after this change goes through. The problem right now is that you have to know these weird platform specific formats exist and then use stuff like readBuffer to get the data.

I think we might end up missing some formats on the initial implementation but I’d expect that we’d add them through follow up PRs. If there are particular formats you are interested in, feel free to mention them here.

Copy link
Member

@erickzhao erickzhao left a comment

Choose a reason for hiding this comment

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

RFC LGTM

Copy link
Member

@reitowo reitowo left a comment

Choose a reason for hiding this comment

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

RFC LGTM

* `clipboardType` string (optional) - Can be `selection` or `clipboard`; default is `clipboard`. `selection` is only available on Linux.
* This API will be modified to bring into spec compliance with the [Web API clipboard.read](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/read)
* Returns a Promise that resolves with an array of [ClipboardItem](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem) objects containing the
clipboard's contents. The promise is rejected if permission to access the clipboard is not granted.
Copy link
Member

Choose a reason for hiding this comment

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

Presumably this permission check wouldn't apply in the main process?

* `clipboard.read([clipboardType])`
* `clipboardType` string (optional) - Can be `selection` or `clipboard`; default is `clipboard`. `selection` is only available on Linux.
* This API will be modified to bring into spec compliance with the [Web API clipboard.read](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/read)
* Returns a Promise that resolves with an array of [ClipboardItem](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem) objects containing the
Copy link
Member

Choose a reason for hiding this comment

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

From the ClipboardItem docs, it seems like a single ClipboardItem has a types array which lets it contain multiple clipboard types. Would we need to return an array of ClipboardItem, or would one ClipboardItem be sufficient?

* This API will be modified to bring into spec compliance with the [Web API clipboard.read](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/read)
* Returns a Promise that resolves with an array of [ClipboardItem](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem) objects containing the
clipboard's contents. The promise is rejected if permission to access the clipboard is not granted.
* Ensure that raw formats are preserved
Copy link
Member

Choose a reason for hiding this comment

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

If a raw format doesn't map to a pre-defined (or custom electron application) MIME type, how would we expose the additional raw formats?

I believe on Windows you can use GetClipboardFormatName to get a string representation of the format (though annoyingly, for built-in formats, this returns an error because you're just supposed to know what those formats are 😅)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending-review Waiting for reviewers to give feedback on the PR specifications

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants