-
Notifications
You must be signed in to change notification settings - Fork 37
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
Specify order of flavors exported to macOS's pasteboard #137
Comments
Ah, yes. We had to deal with this problem specifically with Pages. The justification of their behavior comes from:
That Pasteboard Programming Guide's mentioning of preferring the most fluid / rich content type is relatively new thing. It happened as a result of continuity pasteboard since iOS's UIPasteboard didn't use to allow specifying the ordering between types. This ordering issue is precisely what prompted us to suggest that the types in Now, I'm not certain that there is much we can do in terms of specification since this issue is very much platform dependent. We have a bunch of heuristics to determine in what order we want to write stuff into the pasteboard with various compatibility hacks but that's not something we want to standardize as we can't even agree on what to do in macOS vs. iOS. |
I'm gonna just drop this thing right here for ourselves... rdar://problem/35158037 |
Which compatibility hacks? It would be nice specify this somehow. Perhaps even OS specific? Otherwise, it's hard for browsers to stay compatible. |
I don't think that makes much sense. Maybe it cold be an informal note somewhere but it certainly doesn't belong in an official W3C specification for the clipboard API. Having said that, you can take a look at https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/platform/mac/PlatformPasteboardMac.mm and all the changes we made to that file in recent years. |
@tomayac We also need to look into this before Chrome ships the copied SVG. @snianu Can you confirm that the current implementation in Chrome supports ordering ClipboardItem? |
@snianu From a simple approach, can we put |
Microsoft's development documentation has similar instructions:
|
It is difficult for the browser to determine which format is richer in information. For example, when copying In my testing, I found that Safari has the ability to customize the order in which information is written to the clipboard based on the type the developer passes in the ClipboardItem. For better interoperability, the specification may be able to move in that direction.. |
Adding @evanstade to this thread as well. I agree that maintaining order in the system clipboard is important for native apps to pick the most desired format during paste. On Windows, the guidance is to place the high fidelity formats at the top:
I'm not sure if we can standardize the ordering of the formats in the system clipboard, but perhaps we can maintain the order of the formats in the |
Yes, Safari currently does that. navigator.clipboard.write([
new ClipboardItem({
// Adjusting the order here in Safari will change the order in which it is written to the clipboard
'image/png': new Promise(async resolve => {
const response = await fetch("https://upload.wikimedia.org/wikipedia/commons/8/89/PNG-Gradient.png");
resolve(await response.blob());
}),
'text/plain': new Promise(resolve => {
const blob = new Blob([text], { type: 'text/plain' });
resolve(blob);
}),
})
]); |
Added Agenda+ tag to discuss in the EditingWG meeting. |
The Web Editing Working Group just discussed The full IRC log of that discussion<dandclark> topic: https://github.com//issues/137<dandclark> github: https://github.com//issues/137 <dandclark> snianu: All 3 browsers have different behaviors <dandclark> ...: Want to standardize the order that formats get written to clipboard <dandclark> ...: Clients tend to read topmost format, expect that to have highest fidelity <whsieh> q+ <dandclark> ...: Chromium has fixed order, I think FF order is fixed but it seems to be wrong <dandclark> ...: Custom formats seem to get on the top, image formats come after HTML <dandclark> ...: Safari I haven't tested personally, someone said it preserves formats of web author <dandclark> whsieh: We do preserve order, that's intentional <dandclark> ...: Article you pointed out is old. Modern APIs use NSItemProvider where order does matter. Same as Windows, highest fidelity are on the top. Devs are expected to go through types in order of fideliety <dandclark> ...: Idea is that richest supported format is the one they should consume <dandclark> ...: In Safari we preserve order for that purpose <dandclark> snianu: If the web authors write img after text/plain, and the user pastes in native app, does the it get reordered? <dandclark> whsieh: We preserve order in that case <dandclark> snianu: I wanted to discuss that; I don't know if web authors are aware that order is important. Would be good to standardize it. Should we define fixed order? <dandclark> ...: Or leave it up to web authors? <dandclark> smaug: Should leave it up to the webpage authors, following what Safari's doing. Don't know why Firefox is doing something else, it's some legacy behavior <dandclark> snianu: FF had some surprising results <dandclark> smaug: chromium's order is also strange <dandclark> ...: We should follow Safari's model here <dandclark> snianu: If we do that, does it affect DataTRansfer APIs? <dandclark> ...: In Chromium we have fixed order for those, would be hard to have different order based on APIs being used by web authors <dandclark> ...: In browser process where we interact with sys clipboard, can't know if we should preserve order or the legacy behavior <dandclark> ...: So that could cause breakage if we change it <dandclark> ...: Original issue was opened because of image pasting issues in Pages and Keynote. <dandclark> ...: I only heard reports of Pages failures with Firefox. Has anyone investigated why it's failing? <dandclark> ...: Someone commented on issue that order is the reason the paste failed. But my experience testing Office and Windows stuff, order matters when pasting images and plaintext. <dandclark> ...: I don't see issues with paste, svg is still pasted in native app <dandclark> smaug: I wonder if in Windows apps just do different things vs MacOS <dandclark> smaug: On Windows it's worked the same since Win32 <dandclark> (That last comment was snianu, not smaug) <dandclark> smaug: We should investigate if we can follow Safari's model elsewhere, see what breaks. Hard to know otherwise. <dandclark> snianu: Proposal is to make changes in nightly build in both APIs? Worried about changing DataTransfer. I'm sure there will be breakage in Office. <dandclark> smaug: What's the behavior in Safari for DataTransfer? <dandclark> whsieh: Not sure, I think we respect order, if we don't we should. <dandclark> ...: as we try to align DataTransfer to more modern async clipboard <dandclark> johanneswilm: Are we proposing spec changes? <dandclark> snianu: Spec says order is specified by web author. <dandclark> ...: but spec is iterating clipboard item, doesn't define any order there. <dandclark> ...: This order is more from system/OS perspective, if you mess that up then native app reads lower fidelity format <dandclark> johanneswilm: So that's what we're sticking with, FF will try this out <dandclark> smaug: It can't be just us <dandclark> ...: Needs to be all browsers on Windows. Also don't know about Linux <dandclark> snianu: Couldn't find Linux guidance <dandclark> ...: MacOS & Windows, there are specific guidelines that richest format goes on top <dandclark> smaug: Could be tricky to change if apps rely on specific behavior on Win <dandclark> sanketj_: Is it defined about which formats are the most important? <dandclark> smaug: I don't know which is more important. Would expect maybe HTML because it has more semantic info vs image <dandclark> whsieh: But if you're copying single image...It's context dependent. <dandclark> johanneswilm: What are we expecting from this meeting? <dandclark> snianu: Was wondering if there's real issue here. If no then we're hesitant to change anything since this is very fragile. <dandclark> ...: If we break copy/paste with old office apps, very hard to fix <dandclark> ...: I initially proposed to keep Safari's behavior, because that's how the spec is written, but thought deeply about how to make the change in Chromium, ran into this issue that we can't figure what order the author chose <dandclark> ...: From my own experience here it's very hard to change. <dandclark> Christine Hollingsworth: Don't have a formal opinion, would be nice to standardize but only if reasonably possible <dandclark> smaug: Can keep issue open but not be very active <dandclark> sanketj_: If we mark it as closed, say we'll never do it. Leaving it open says we might do it in future. What new data would be needed such that we might do it ? <dandclark> smaug: More testing, trying Safari's behaivor on Windows <dandclark> sanketj_: Seems like it was a FF bug, pasting into Pages. Are you fixing that bug? <dandclark> smaug: That was fixed years ago, looking at what was changed. Looks like the order was changed <dandclark> ...: But it's not a generic solution, not following Safari's model. Order is still fixed. <dandclark> sanketj_: You take image to be highest pri? <dandclark> smaug: At least on mac <dandclark> sanketj_: Can you confirm what's your order on different platforms? We could get inventory on different orders browsers have today on different platforms <dandclark> ...: Based on that we could figure out what we need to change to all be spec compliant <dandclark> smaug: Sounds good <dandclark> ...: snianu , smaug , whsieh to document these in the issue for their respective browsers |
Summary of Gecko's behavior on different platformTest script: const clipboardItem = new ClipboardItem({
"text/plain": "text",
"image/png": imageBlob,
"text/html": "<html></html>",
});
navigator.clipboard.write([clipboardItem]); Order in system clipboard:
On Linux and Windows, we use the order of the formats in the ClipboardItem as specified by the web authors. And DataTransfer behave the same. |
The Web Editing Working Group just discussed The full IRC log of that discussion<sanketj_> Topic: Specify order of flavors exported to macOS's pasteboard<sanketj_> github: https://github.com//issues/137 <sanketj_> snianu: Not sure has changed since last discussion. <sanketj_> ...: Chromium has fixed order. Order determined when clipboard item created. Order preserved when writing to clipboard. <sanketj_> ...: Not sure if it is possible to standardize order of formats written to clibpoard. <sanketj_> ...: On Windows, there is some historical precedence from legacy apps. <sanketj_> ...: May be different orders are needed on different platforms. <sanketj_> sanketj: Last time we discussed we wanted to find out order from each browser. Chrome and Firefox seem to do different things, not sure if can be reconciled without compat problems. <sanketj_> smaug: Doesn't Safari write based on author order? <snianu> my zoom client crashed <sanketj_> snianu: Sounds right. But we may have to leave it up to the UA. Possibly based on platform. <sanketj_> smaug: Does Chromium have fixed order, regardless of author choice? <sanketj_> sanketj: Chromium has fixed order, seems to be written in that order on all platforms. <sanketj_> wshieh: List is order of fidelity? Highest to lowest? <sanketj_> sanketj: Yes. <sanketj_> wshieh: Similar concept on Mac/iOS with Webkit, but we go with the developer's ordering choice. <sanketj_> wshieh: MacOS documentation also old. Points to older APIs. <sanketj_> johanneswilm: Are we likely to get agreement on a behavior across browsers here? <sanketj_> smaug: Not sure if not possible or no strong opinion. <sanketj_> ...: May need investigation from all browsers. <sanketj_> sanketj: There is risk with making these changes. Is it worth doing? <sanketj_> johanneswilm: How would this make things better? <sanketj_> smaug: Just consistency. <sanketj_> johanneswilm: Spec already mentions you can't rely on the order. <sanketj_> smaug: Depends on what native apps choose. <sanketj_> johanneswilm: Let's set this aside for further investigations from other browsers? <sanketj_> smaug: Why does Chromium have the current order? <sanketj_> snianu: Not sure why fixed order was chosen. <sanketj_> ...: Do want consistent order of formats between DataTransfer and async clipboard API. <sanketj_> ...: Different order between copy/paste and async clipboard API may lead to inconsistent copy/paste for users. <sanketj_> ...: OS like Windows specify higher fidelity formats go on top. <sanketj_> sanketj: Doesn't Windows spec mention order? <sanketj_> snianu: Windows spec doesn't specify exact order, but says highest fidelity format should go on top. <sanketj_> ...: Risk is that if the authors provide a different order, then that isn't respected. <sanketj_> ...: Changing browser orders carries risk of copy/paste issues since native apps hard to change. <sanketj_> sanketj: Can someone post in the issue to confirm the active web dev impact? Original issue seems to be a Firefox bug that fixed a long time ago. <sanketj_> johanneswilm: If someone can help take this further, let us know. If not, let's move on until there is more info. |
When exporting images to the clipboard (via right-click and "Copy Image"), Chrome and Firefox currently order the flavors differently on macOS's pasteboard.
Chrome adds:
Firefox adds:
Despite Apple's Pasteboard Programming Guide requiring the pasteboard readers to not rely on the order:
"A pasteboard reader must find the data type that best suits its capabilities (if any). Typically, this means selecting the richest type available. In the previous example, a rich text editor might provide RTFD, RTF, and NSString representations of copied data. An application that supports rich text but without images should retrieve the RTF representation; an application that only supports plain text should retrieve the NSString object, whereas an image-editing application might not be able to use the text at all."
some applications, like Pages rely on it. See here.
So for compatibility, the order should be specified.
The text was updated successfully, but these errors were encountered: