Copying selected data generates outer HTML into the clipboard
Categories
(Core :: DOM: Serializers, defect)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox148 | --- | fixed |
People
(Reporter: edgar, Assigned: edgar)
References
(Blocks 7 open bugs, )
Details
Attachments
(2 files)
There is a difference on content serialization result between Firefox and Chrome. For example. if you select all content on https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=13533 and press Ctrl+C, then check the clipboard content:
The data that Firefox put into clipboard:
<div>
<span>First Line</span>
<div>
<span>Second Line</span>
</div>
<span>Third Line</span>
</div>
The data the Chrome put into clipboard:
<meta charset='utf-8'><span style="color: rgb(0, 0, 0); font-family: Times; font-size: medium; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">First Line</span><span style="color: rgb(0, 0, 0); font-family: Times; font-size: medium; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"></span><div style="color: rgb(0, 0, 0); font-family: Times; font-size: medium; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><span>Second Line</span></div><span style="color: rgb(0, 0, 0); font-family: Times; font-size: medium; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Third Line</span>
A key difference is that Firefox includes the outer <div>, whereas Chrome does not. I think this is https://github.com/w3c/clipboard-apis/issues/49 where spec is verge about it.
Comment 1•1 year ago
|
||
Per discussion with the Editing WG, we should try to match the behavior of Chromium and WebKit here.
Updated•1 year ago
|
| Assignee | ||
Updated•10 months ago
|
Updated•6 months ago
|
Updated•6 months ago
|
Updated•6 months ago
|
Updated•6 months ago
|
Comment 2•6 months ago
|
||
Is this caused by the difference of the serializers? I wonder if the other browsers might shrink the selection range when "Select All" to first/last meaningful leaf node start/end. Actually, I got the following range when I do "Select All" on Chrome.
Range {commonAncestorContainer: div, startContainer: text, startOffset: 0, endContainer: text, endOffset: 10, …}
collapsed: false
commonAncestorContainer: div
endContainer: text
endOffset: 10
startContainer: text
startOffset: 0
| Assignee | ||
Comment 3•5 months ago
|
||
"Select All" is a different case. This case is about select all text manually by mouse.
Chrome and us both has same range as below,
Range { commonAncestorContainer: div, startContainer: #text, startOffset: 0, endContainer: #text, endOffset: 10, collapsed: false }
collapsed: false
commonAncestorContainer: <div>
endContainer: #text "Third Line"
endOffset: 10
startContainer: #text "First Line"
startOffset: 0
And our serialized html content for clipboard copying includes the common ancestor element, whereas Chrome doesn't.
Comment 4•5 months ago
|
||
Oh, thank you for clarifying.
And it seems that this bug is more important on Android. I've not realized that I'm a victim of this bug. When I copy all text in a heading element on Firefox for Android and paste it to another Android app, the pasted text ends with 2 line breaks. I guess the outer heading element of the text in clipboard causes the trailing line breaks when it's pasted into another app's text field. (Although I'm not familiar with clipboard handling/API of Android.)
| Assignee | ||
Comment 5•5 months ago
|
||
(In reply to Masayuki Nakano [:masayuki] (he/him)(JST, +0900) from comment #4)
When I copy all text in a heading element on Firefox for Android and paste it to another Android app, the pasted text ends with 2 line breaks. I guess the outer heading element of the text in clipboard causes the trailing line breaks when it's pasted into another app's text field. (Although I'm not familiar with clipboard handling/API of Android.)
Would you mind filing a separated bug with STR? I could take a look and do some investigation. Thanks!
Updated•5 months ago
|
| Assignee | ||
Updated•5 months ago
|
| Assignee | ||
Comment 7•5 months ago
|
||
| Assignee | ||
Comment 8•5 months ago
|
||
| Assignee | ||
Comment 9•5 months ago
|
||
| Assignee | ||
Comment 10•4 months ago
|
||
Updated•4 months ago
|
Updated•4 months ago
|
Updated•4 months ago
|
Comment 11•4 months ago
|
||
Comment 12•4 months ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/2c3c9a4f5113
https://hg.mozilla.org/mozilla-central/rev/8eba4813d61a
Updated•4 months ago
|
Description
•