ClipOps 2

Trying to use clipboard operations (custom types)

Idea

The current Async clipboard APIs specification is out and allows, after permission, JavaScript pages to invoke copy (write to clipboard) or paste (read from clipboard) when they deem it useful. That is very nice as users start to be aware that permissions is something they could give and trust. As we are on the web, it means that what is copied remains sanitized: a picture is rendered then re-serialized, HTML gets devoided of anything slightly suspicious, the rest is removed.

But what is more exciting is that custom types are coming: JavaScript in a page can, for implementing browsers, specify content types that will get transmitted for other apps or other web pages to use.

A proposed specification pull-request (an amendment) has been made that would allow the content-types to be named with a prefix "web " (web followed by a space, this idea of @annevk makes it impossible to parse a media type out of that) to be put into the clipboard using the same operations. Reveiving web-pages would look for the same pattern and are warned that this is raw content: Depending on the processing, the content must be sanitized (e.g. if put within a web-page, one should avoid to transport trackers or candidate web page attacks).

Application

Here we have a small equation in MathML (from here) and a button to copy it:

P ν μ ( cos θ ) = 2 μ + 1 ( sin θ ) μ π 1 / 2 k = 0 Γ ( ν + μ + k + 1 ) Γ ( ν + k + 3 2 ) ( μ + 1 2 ) k k ! sin ( ( ν + μ + 2 k + 1 ) θ )

Note that the copy only works on Blink-generation Chromium (or Edge) from version 105 upwards. There, the MathML does only display if you activate "Experimental Web Platform features" from the "chrome://flags/" URL!

A you can see in the source, the copy button writes two blobs into the clipboard:

Result

Expected: On some platforms and using some browsers the clipboard flavour for MathML should appear so that desktop apps could consume what was copied (e.g. from a web-page of a textbook). We're close to this.

The obtained result on my macOS today (2022-09-16) is close to this:

Conclusion

Web pages will be able to produce rich MathML content using JavaScript. Most probably formula input-editors, formula enrichment or display systems such as MathJax, web-sites with lots of formulæ such as DLMF or wikipedia will all be able to take advantage of this. That looks like a content that is ready to be used by desktop apps, once they know that they have the proper sanitization in place.

It also seems that desktop apps can produce this. Well... it seems interoperable!

I feel slightly unsafe on the permissions: Can it be that I forget that I allowed access to clipboard? Probably the permissions won't last long. As another drawback this implementation is not yet standardized... which makes it fragile.

Optimistic note: Since the code in the page is doing the copy, it is also responsible to support the selection of a portion of the expression to be copied. It is true that this is not as declarative as simple markup but it will let page authors get their say in the selection: e.g. extending a selection of a+b-c+5 from "+b-" to "a+b+c".

Acknowledgement

Thanks @snianu for pushing and developing the custom types spec, for @tomayac for making the helpful blog page and demo at TPAC 2022, for the project Fugu's streamlining of APIs and for @garykac for keeping on track of the clipboard API spec.