Skip to content
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

html5 clipboard #74

Closed
totaam opened this issue Mar 9, 2017 · 30 comments
Closed

html5 clipboard #74

totaam opened this issue Mar 9, 2017 · 30 comments

Comments

@totaam
Copy link
Collaborator

totaam commented Mar 9, 2017

split from Xpra-org/xpra#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)
@totaam
Copy link
Collaborator Author

totaam commented Mar 9, 2017

2017-03-09 14:10:50: antoine uploaded file html5-clipboard-promise.patch (0.9 KiB)

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

@totaam
Copy link
Collaborator Author

totaam commented Mar 9, 2017

2017-03-09 14:11:24: antoine uploaded file html5-clipboard-sleep.patch (0.5 KiB)

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

@totaam
Copy link
Collaborator Author

totaam commented Mar 9, 2017

2017-03-09 14:42:10: antoine changed owner from antoine to afarr

@totaam
Copy link
Collaborator Author

totaam commented Mar 9, 2017

2017-03-09 14:42:10: antoine commented


Synchronous Copy EventsIn 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 TypesLinks:

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 [/browser/xpra/trunk/src/xpra/gtk_common/gtk_view_clipboard.py 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)

@totaam
Copy link
Collaborator Author

totaam commented Mar 11, 2017

2017-03-11 09:06:28: antoine commented


Minor improvements in r15273.

@totaam
Copy link
Collaborator Author

totaam commented Apr 3, 2017

2017-04-03 16:41:01: antoine commented


Some reports of clipboard issues with:

@totaam
Copy link
Collaborator Author

totaam commented Apr 3, 2017

2017-04-03 19:50:47: Denis01 commented


version - html5-2.0.1-2.15507
Chrome.
1)Copy from windows into html client does not work (neither for EN no for other keyboards). Nothing is pasted.
2) Copy from html client into windows works well for EN and does not work for unicode (pastes but wrong symbols)

@totaam
Copy link
Collaborator Author

totaam commented Apr 4, 2017

2017-04-04 09:45:16: antoine changed owner from afarr to Denis01

@totaam
Copy link
Collaborator Author

totaam commented Apr 4, 2017

2017-04-04 09:45:16: antoine commented


@denis01 please specify:

  • full client OS version
  • exact chrome version
  • what you tried to copy and from where (plain text? from notepad?)
  • how you pasted: control-V? right click?
  • into what application?

The issue with Unicode characters on the clipboard should be fixed in r15512. (works for me)

@totaam
Copy link
Collaborator Author

totaam commented Apr 5, 2017

2017-04-05 13:22:32: Denis01 commented


CentOS Linux 7.3.1611
xpra X11 version 2.1-15507 64-bit
Chrome 57.0.2987.133
Plain text. Notepad.

Getting worse. Now after several operations Copy-Paste (HTML->Notepad, Notepad->HTML) even in EN system stops to copy anything and keeps 2 splited clipboars (one as OS clipboard, another as HTML client clipboard)

Probably r15512 will fix. but still no update available.

@totaam
Copy link
Collaborator Author

totaam commented Apr 8, 2017

2017-04-08 12:44:27: antoine changed owner from Denis01 to afarr

@totaam
Copy link
Collaborator Author

totaam commented Apr 8, 2017

2017-04-08 12:44:27: antoine commented


I suspect that the problem may be with the PRIMARY buffer selection which can generate hundreds of clipboard requests and cause the system to turn off the clipboard synchronization as a precaution. This would have shown as a warning in the log output, but @denis01 did not include any output so it is impossible to tell.
If that's the case, we can deal with this problem as part of Xpra-org/xpra#1400.

@afarr: does this new clipboard code work well enough for you?

@totaam
Copy link
Collaborator Author

totaam commented Apr 10, 2017

2017-04-10 06:22:37: Denis01 commented


hello,
yes, too many requests to clipboard (details below).
And I noticed that it occurred when tried to copy multiple lines. For one, two, three..... words in one line it works normally.
is r15512 already published for test?

___________________________________
(gedit:24376): Gtk-WARNING **: Calling Inhibit failed: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files
2017-04-10 00:59:48,881 clipboard disabled: more than 20 clipboard requests per second!
2017-04-10 00:59:48,933 client 1: server set clipboard state to 0 reason was: more than 20 clipboard requests per second!

@totaam
Copy link
Collaborator Author

totaam commented Apr 16, 2017

2017-04-16 07:49:55: Denis01 commented


Hello,
applied changes in r15512 (xpra X11 version 2.1-15507 64-bit, Chrome). Didn't help.
Unicode copy from Notepad to HTML client - don't work
Copy from HTML client in Unicode symbols works but Notepad pastes non correct symbols (in wrong codification).
Other remarks:
even with En keyboard if there is a Space or Enter between words - the copying process is broken

@totaam
Copy link
Collaborator Author

totaam commented May 17, 2017

2017-05-17 06:37:31: antoine commented


@afarr: r15873 fixes the clipboard with macos clients, and we now also have the "swap command and control keys" option on the connect page.
Apple use the "meta" (aka "command") modifier instead of "control". This works reliably for me with chrome, not so well with Safari or Firefox. (someone who really cares about this evil combination of OS and browser could fix this I guess)
Unicode clipboard transfers also worked for me (in both directions with chrome), no idea what comment:9 is about.

PS: this will not be applied to the 2.0 branch that this ticket is for...

@totaam
Copy link
Collaborator Author

totaam commented May 18, 2017

2017-05-18 14:00:59: Denis01 commented


Hello,
HTML client, Chrome, Windows 7
For tests i always use "Cntr-C" for copy and "Cntrl-V" for paste
Libreoffice 5.2

everything seems fine except:

  1. multiline copying.
    From Notepad to XPRA works well but from XPRA to Notepad - not always (but oneline copying works well to both sides)
  2. Copying in UNICODE.
    Somethings one line text(unicode) with spaces doesn't work well from XPRA to Notepad.
  3. if EN keyboard in tray "Cnt-C"+"Cntr-V" works but if RU keyboard in try - neither "Copy" no "Paste" works in XPRA

P.S. Comment:9. Everything works fine. Don't see now any issues. Resolved

@totaam
Copy link
Collaborator Author

totaam commented Aug 8, 2017

2017-08-08 00:07:02: afarr changed owner from afarr to antoine

@totaam
Copy link
Collaborator Author

totaam commented Aug 8, 2017

2017-08-08 00:07:02: afarr commented


Tested with 2.2 16657 fedora 25 server - works reliably for me in chrome as well (text in each direction, including 'non-hexadecimally' entered 'alt-code' unicode on windows and the 'option' characters on osx, with both windows 7 on chrome 59 and osx 10.12 with chrome 60).

Note... while trying to check on the unicode issue above, I found that there seem to be 'unicode' that can be entered on windows with alt-{numeral code}, as indicated here: https://support.office.com/en-us/article/Insert-ASCII-or-Unicode-Latin-based-symbols-and-characters-d13f58d3-7bcb-44a7-a4d5-972ee12e50e0 ... which is what I have been trying to consistently use, and which seems to work with the clipboard.

And, on the other hand, there seems to be some pages I find with a search that indicates the use of unicode with alt and + and then a hexadecimal string (https://en.wikipedia.org/wiki/List_of_Unicode_characters) - which I still have not managed to successfully input, even with the trick of adding a registry value to enable hexadecimal input described here: https://www.johndcook.com/blog/2008/08/17/three-ways-to-enter-unicode-characters-in-windows/.

Tested a little with firefox 53 on osx 10.12 - found that copying from server side and within server side seemed to sync with client-side clipboards and paste correctly everywhere, but the reverse not so much. Copying client-side didn't sync with server-side at all.

I didn't have the fortitude to face Safari.

As a note, with our set ups we have noticed that the html5 client is pulling keyboard layout info from the user's Region &/or Language settings (depending on the platform specifics), so that does seem to be working as you've described above (and therefore expect). We have also noticed that with some platforms (like windows) changing the language settings on a Chrome window before connecting seems to be sufficient to change the keyboard input layout, while on other platforms (OSX) the only way to change (aside from potentially with the menu on the connect.html page which was dodgy for a while) was the Language and Region setting itself.

Not germaine to clipboard, but since keyboard input was mentioned above, thought I'd add it.

In any case, I'll hand this back to you and let you decide whether to keep this around for the Firefox (and Safari?) issues or if you want to close it and make a separate ticket for that issue.

@totaam
Copy link
Collaborator Author

totaam commented Aug 8, 2017

2017-08-08 08:00:20: antoine changed owner from antoine to afarr

@totaam
Copy link
Collaborator Author

totaam commented Aug 8, 2017

2017-08-08 08:00:20: antoine commented


Copying client-side didn't sync with server-side at all.
We can only copy from the client clipboard when we get a paste event from the browser. Usually, this requires the user to hit ctrl+V or to use the browser's "paste" menu entry.
(and just to be clear: this needs to be the "paste" from the local browser's menu, not from anything at the server end..)

With the javascript console enabled and "debug" enabled from the connect dialog, you should be seeing something like this when hitting ctrl+V:

paste event, data= THE-CLIPBOARD-CONTENTS-STRING
Client.js:1 sending clipboard token with data: THE-CLIPBOARD-CONTENTS-STRING

The server end can show the usual (large) corresponding details with "-d clipboard".


WRT keyboard layout, there are improvements in 2.1, see:

  • HTML5 client. Keyboard layout on-fly change #66#comment:3 : can switch the keyboard layout dynamically for some blatantly non english us keys
  • r15479: we use a request to the server, which the server then echoes back to try to figure out which language to use (the http request should include the "accept-language" header which is not accessible to javascript)
    If this doesn't work properly, we should use another ticket.

@totaam
Copy link
Collaborator Author

totaam commented Sep 8, 2017

2017-09-08 11:39:04: antoine changed status from new to closed

@totaam
Copy link
Collaborator Author

totaam commented Sep 8, 2017

2017-09-08 11:39:04: antoine set resolution to worksforme

@totaam
Copy link
Collaborator Author

totaam commented Sep 8, 2017

2017-09-08 11:39:04: antoine commented


Not heard back, closing.

@totaam
Copy link
Collaborator Author

totaam commented Oct 3, 2017

2017-10-03 03:51:50: afarr changed status from closed to reopened

@totaam
Copy link
Collaborator Author

totaam commented Oct 3, 2017

2017-10-03 03:51:50: afarr removed resolution (was worksforme)

@totaam
Copy link
Collaborator Author

totaam commented Oct 3, 2017

2017-10-03 03:51:50: afarr commented


Checking with firefox 55, OSX 10.12, fedora 25 2.2 r17074.

Copying a bit of text in firefox, with the logs running, I see the following.

received a clipboard-token packet  Client.js:181:3
clipboard token: Array [ "clipboard-token", "CLIPBOARD", Array[12], "UTF8_STRING", "UTF8_STRING", 8, "bytes", "e ha descrito", 1, 0 ]  Client.js:181:3
processKeyEvent( false ,  Object { originalEvent: keyup, type: "keyup", isDefaultPrevented: returnFalse(), target: <body>, currentTarget: HTMLDocument → index.html, relatedTarget: undefined, timeStamp: 28301.504882, jQuery3110566577829970913: true, delegateTarget: HTMLDocument → index.html, handleObj: Object, 1 more… } ) key=  keycode= 224  Client.js:181:3
Array [ "key-action", 2, "", false, Array[0], 224, "meta", 224, 0 ]

Trying to paste locally I see no console logs client side (unsurprisingly), no server logs (also not terribly surprising), and I can see that the contents of the clipboard token haven't sync'd.

Likewise, while trying to paste something copied client-side results in pasting the contents of the not-sync'd server-side clipboard... and, the only console logs I see when trying to paste is some part of this:

received a cursor packet  Client.js:181:3
got mouse click at  715 82  Window.js:202:3
received a draw packet  Client.js:181:3
may_paint_now() paint pending= 0 , paint queue length= 1  Window.js:202:3
do_paint( 1779  bytes of   rgb32  data  200 x 24  at  652 , 38 ) focused= true  Window.js:202:3
got  19200 to paint with stride 800  Window.js:202:3
decode time for  rgb32  sequence  72 :  2695  Client.js:181:3
received a ping packet  Client.js:181:3
got mouse click at  715 82  Window.js:202:3
processKeyEvent( true ,  Object { originalEvent: keydown, type: "keydown", isDefaultPrevented: returnFalse(), target: <body>, currentTarget: HTMLDocument → index.html, relatedTarget: undefined, timeStamp: 31547.299677000003, jQuery3110869640561087128: true, delegateTarget: HTMLDocument → index.html, handleObj: Object, 1 more… } ) key=  keycode= 224  Client.js:181:3
Array [ "key-action", 2, "", true, Array[1], 224, "meta", 224, 0 ]  Client.js:181:3
processKeyEvent( true ,  Object { originalEvent: keydown, type: "keydown", isDefaultPrevented: returnFalse(), target: <body>, currentTarget: HTMLDocument → index.html, relatedTarget: undefined, timeStamp: 31731.410624, jQuery3110869640561087128: true, delegateTarget: HTMLDocument → index.html, handleObj: Object, 1 more… } ) key=  keycode= 86  Client.js:181:3
Array [ "key-action", 2, "v", true, Array[1], 86, "v", 86, 0 ]  Client.js:181:3
Array [ "key-action", 2, "v", false, Array[1], 86, "v", 86, 0 ]  Client.js:181:3
processKeyEvent( false ,  Object { originalEvent: keyup, type: "keyup", isDefaultPrevented: returnFalse(), target: <body>, currentTarget: HTMLDocument → index.html, relatedTarget: undefined, timeStamp: 31907.385251, jQuery3110869640561087128: true, delegateTarget: HTMLDocument → index.html, handleObj: Object, 1 more… } ) key=  keycode= 224  Client.js:181:3
Array [ "key-action", 2, "", false, Array[0], 224, "meta", 224, 0 ]  Client.js:181:3
processKeyEvent( false ,  Object { originalEvent: keyup, type: "keyup", isDefaultPrevented: returnFalse(), target: <body>, currentTarget: HTMLDocument → index.html, relatedTarget: undefined, timeStamp: 31923.386725, jQuery3110869640561087128: true, delegateTarget: HTMLDocument → index.html, handleObj: Object, 1 more… } ) key=  keycode= 86  Client.js:181:3
Array [ "key-action", 2, "v", false, Array[0], 86, "v", 86, 0 ]  Client.js:181:3
received a draw packet  Client.js:181:3
may_paint_now() paint pending= 0 , paint queue length= 1  Window.js:202:3
do_paint( 144  bytes of   rgb32  data  2 x 18  at  676 , 41 ) focused= true  Window.js:202:3
got  144 to paint with stride 8  Window.js:202:3
decode time for  rgb32  sequence  73 :  1690  Client.js:181:3
received a ping packet  Client.js:181:3

... which just seems to be the cursor & key events of a command-v.
With a fresh server to double check the pasting, the server-side clipboard is clear and nothing pastes.

@totaam
Copy link
Collaborator Author

totaam commented Nov 14, 2017

2017-11-14 15:36:25: antoine changed status from reopened to closed

@totaam
Copy link
Collaborator Author

totaam commented Nov 14, 2017

2017-11-14 15:36:25: antoine set resolution to fixed

@totaam
Copy link
Collaborator Author

totaam commented Nov 14, 2017

2017-11-14 15:36:25: antoine commented


The bug seems to only affect Firefox, so I am closing this ticket and will follow up in Xpra-org/xpra#1689.

@totaam totaam closed this as completed Nov 14, 2017
@totaam
Copy link
Collaborator Author

totaam commented May 16, 2018

2018-05-16 06:44:49: antoine commented


See also async clipboard api: #72

@totaam totaam transferred this issue from Xpra-org/xpra Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant