xpra icon
Bug tracker and wiki

Opened 2 weeks ago

Last modified 2 weeks ago

#1461 new enhancement

html5 clipboard

Reported by: Antoine Martin Owned by: alas
Priority: major Milestone: 2.0
Component: html5 Version: trunk
Keywords: Cc:


split from #1424

Code added in r15242.

Still TODO:

  • test with macosx, which may use a different value for the control key (apple key or whatever they decide to rename it to)
  • first few copy events don't always work (token is at the wrong end?)
  • would be nice to try to wait for the real clipboard contents (instead of the latest primary clipboard selection) so that applications that cook the clipboard data can be handled better (ie: browsers with google docs, etc) - but blocking the clipboard paste event handler may also block the network code that receives the response from the server?
  • maybe handle more mime types (may help with the issue above)

Attachments (2)

html5-clipboard-promise.patch (879 bytes) - added by Antoine Martin 2 weeks ago.
use a promise to delay handling the clipboard copy request - does not work
html5-clipboard-sleep.patch (561 bytes) - added by Antoine Martin 2 weeks ago.
busy wait for 150ms so the server can handle the clipboard copy event

Download all attachments as: .zip

Change History (4)

Changed 2 weeks ago by Antoine Martin

use a promise to delay handling the clipboard copy request - does not work

Changed 2 weeks ago by Antoine Martin

Attachment: html5-clipboard-sleep.patch added

busy wait for 150ms so the server can handle the clipboard copy event

comment:1 Changed 2 weeks ago by Antoine Martin

Owner: changed from Antoine Martin to alas

Synchronous Copy Events

In order to give enough time to the server so that it can process the copy request and gives us the correct clipboard value to use, I've tried using an async function (see attachment/ticket/1461/html5-clipboard-promise.patch) but the javascript clipboard API doesn't handle the promise as a value. (not surprising since this would bypass the clipboard access restrictions)

The busy wait approach (see attachment/ticket/1461/html5-clipboard-sleep.patch) does work, but:

  • it's a busy wait... ugly, burns CPU cycles for nothing, jquery also moans that it takes too long to execute
  • we would need to calculate a reasonable delay (hardcoded at 150ms in the patch), based on the RTT time (ping time) plus the time it takes for client applications to handle the event. (which can be anything.. it can even time out)
  • ideally we would exit the busy loop if we get a clipboard packet (would need a counter for "clipboard" clipboard inbound packets)
  • we still need the primary clipboard data as backup, in case the response doesn't arrive in time and also because we have no way of knowing when a "copy" button is clicked on... (and we don't want to delay all clicks just in case they happen to be on a clipboard button!)

So all in all, I'm not sure it is worth implementing. But maybe it helps with things like google docs? (not tested)

Mime Types


Doing a quick test with google chrome, copying some text on a page (all pages including google docs seem to give the same results) and viewing the list of targets that chrome provides for the clipboard using our view clipboard tool we see: STRING, UTF8_STRING, TEXT, text/plain and text/html. (TIMESTAMP and SAVE_TARGETS can be ignored)

So we should probably handle "text/html" server side and send more than one target - at the moment, we only send the first match (usually "UTF8_STRING").
That's going to be difficult: we have to request each target, those requests are asynchronous and the token packet is only meant to carry one value at a time..
On the plus side, this may help improve clipboard support for "greedy" platforms (win32 and osx).

Copying from the OS to the browser, we currently only request "text/plain", but we should be able to handle more than that. Even image formats if we wanted.
The difficulty in this direction is that with asynchronous clipboards (X11), we can't set multiple values so we would need to set multiple targets and keep a cache of the value for each target - then reply with the correct cached value if and when the server-side application requests it. Messy.

@afarr: how does that work for you? (note: as per ticket description, this has not been tested on osx and its special keycode for "control" may need tweeking)

Last edited 2 weeks ago by Antoine Martin (previous) (diff)

comment:2 Changed 2 weeks ago by Antoine Martin

Minor improvements in r15273.

Note: See TracTickets for help on using tickets.