Skip to content

Conversation

@nmggithub
Copy link
Contributor

@nmggithub nmggithub commented Jan 29, 2026

Description of Change

This is my attempt to resolve #49466. I don't think it's quite ready, so I'm opening it as a draft PR. I welcome comments and critiques to help refine this.

I've added the ability to define the privacy of a write to the clipboard. While the original issue was requesting for the Apple platform, this PR should be cross-platform (to the extend that Chromium upstream actually uses the API's I'm depending on).

Upstream API's Used

(links pinned to Chromium 144.0.7559.60, the version used on the current major: Electron 40.0.0)

Our clipboard API uses the ScopedClipboardWriter class from upstream to manage writing to the clipboard. This class has a private member variable called privacy_types_ that holds an enumeration of privacy settings for a write to the clipboard.

Unfortunately, that member variable isn't writable directory, and the only mechanisms for manipulating it are the functions MarkAsConfidential() and MarkAsOffTheRecord(). To avoid patching Chromium, I simply take these and expose them as mutually-exclusive values for a privacy option in the clipboard writing API's in JS-land. I took the "privacy type" name for the name in of the enum in C++-land (even though it's now not really a one-to-one mapping) because I wasn't sure what else to call it.

Local Testing

Final note: while this does compile and build, I haven't fully tested if the behavior actually works as I expect it to. I plan to do so soon, though.

I have tested this briefly between my MacBook and my iPad and it seems to work well enough.

Release Notes

Notes: Added clipboard privacy options to clipboard writing API's.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Jan 29, 2026
: ui::ClipboardBuffer::kCopyPaste;
}

[[nodiscard]] electron::api::Clipboard::PrivacyType GetClipboardPrivacyType(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not a fan of using an impure function here, but it follows the pattern of GetClipboardBuffer.


* `text` string
* `type` string (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
* `privacy` string (optional) - Can be `confidential`, `off-the-record`, or `none`. Default is `none`.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A note on approach:

As mentioned, I didn't want to patch Chromium, so I tied this to the two (seemingly) different options provided upstream. However, in practice, it seems there isn't much of a difference between the two in ordinary use. MarkAsConfidential() does add one more flag (kNoDisplay) to privacy_types_ than MarkAsOffTheRecord(). However, after perusing the Chromium source code, it seems that flag is only used internally to diverge behavior in one very specific circumstance:

  1. When kNoDisplay is present in privacy_types_, Chromium merely sets a flag on the current clipboard item by way of a nil data payload for a custom type.
  2. That status is only checked by a IsMarkedByOriginatorAsConfidential() function...
  3. ...which is only ever used by code regarding the omnibox, which isn't a feature in Electron.

Perhaps privacy should just be a boolean. But I wonder if these two options will have more of a distinction upstream in the future.

@nmggithub nmggithub marked this pull request as ready for review January 29, 2026 19:08
@VerteDinde VerteDinde added semver/minor backwards-compatible functionality api-review/requested 🗳 labels Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-review/requested 🗳 new-pr 🌱 PR opened recently semver/minor backwards-compatible functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clipboard api support security options

2 participants