Skip to content

[Clipboardchange event API] - Update APIs available in all platforms #974

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions ClipboardAPI/clipboard-change-event-explainer.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,14 @@ One clear issue with this approach is that we are providing all the methods of D

### 6.1 APIs provided by all OS to listen to clipboardchange event:

| OS | API |
| OS | Native API available |
|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Windows | We can use the [AddClipboardFormatListener](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-addclipboardformatlistener) function (winuser.h) which posts a [WM_CLIPBOARDUPDATE](https://learn.microsoft.com/en-us/windows/win32/dataxchg/wm-clipboardupdate) message whenever the clipboard changes. |
| MacOS | No API provided, need to poll OS clipboard for changes |
| Linux | TBD |
| ChromeOS | TBD |
| Android / iOS | TBD |
| Windows | ✔ We can use the [AddClipboardFormatListener function (winuser.h)](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-addclipboardformatlistener) which posts a [WM_CLIPBOARDUPDATE](https://learn.microsoft.com/en-us/windows/win32/dataxchg/wm-clipboardupdate) message whenever the clipboard changes. |
| MacOS | ✘ No API provided, need to poll OS clipboard for changes. To detect clipboard changes, we will poll for value changes to “[changecount](https://developer.apple.com/documentation/uikit/uipasteboard/changecount?language=objc)” provided by the OS which should be more efficient than polling entire contents. |
| Linux X11/Wayland | ✔ In Chromium, the Wayland/X11 implementation of clipboard already calls ui::ClipboardMonitor on clipboard change, so no further changes should be required. - X11 mechanism [code](https://source.chromium.org/chromium/chromium/src/+/main:ui/base/x/x11_clipboard_helper.cc;drc=d815f515138991af2aa5b1d07c64906fd8a7366b;l=68), Wayland mechanism [code](https://source.chromium.org/chromium/chromium/src/+/main:ui/ozone/platform/wayland/host/wayland_data_device.cc;drc=d815f515138991af2aa5b1d07c64906fd8a7366b;l=182) |
| Android | ✔ API to monitor clipboard change available - [here](https://developer.android.com/reference/android/content/ClipboardManager.OnPrimaryClipChangedListener). |
| iOS | ✔ [changedNotification](https://developer.apple.com/documentation/uikit/uipasteboard/changednotification) API available. Note that this API and the types API both don't require any user attention to be used unlike other APIs which read clipboard contents on iOS. |
| ChromeOS | ✔ By default Chrome uses the custom in-memory implementation of the clipboard - [ui::ClipboardNonBacked](https://source.chromium.org/chromium/chromium/src/+/main:ui/base/clipboard/clipboard_non_backed.h), which already invokes [ui::ClipboardMonitor::NotifyClipboardDataChanged()](https://source.chromium.org/chromium/chromium/src/+/main:ui/base/clipboard/clipboard_monitor.h;drc=e7eae5389783001142ba2134e853e987a2d3fe50;l=34) upon clipboard change. It can also use Ozone clipboard implementation from Linux when `--use-system-clipboard` is supplied to the chrome binary; then it will just use the same implementation as on Linux. |

### 6.2 Permission prompt mechanism in various browsers

Expand Down