Open Bug 1542530 Opened 7 months ago Updated 5 months ago

Selection.toString() return an empty string


(Core :: Serializers, defect, P3, minor)

66 Branch



Tracking Status
firefox-esr60 --- wontfix
firefox66 --- wontfix
firefox67 --- fix-optional
firefox68 --- wontfix


(Reporter: mad1ost, Assigned: baku, NeedInfo)




(4 keywords)


(4 files)

User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 YaBrowser/ (beta) Yowser/2.5 Safari/537.36

Steps to reproduce:

I select some text with mouse on (I showed the mouse movement on the attachment).

Actual results:

Selection.toString() return an empty string

Expected results:

as well as Range.toString() return a text

I can reproduce the issue on Nightly68.0a1 windows10.


  1. Open
  2. Drag selection from left side blank area of "T" and to the right
  3. Evaluate window.getSelection().toString() in Web Console

Actual Results:

  • window.getSelection().toString();, then it returns "".
  • window.getSelection().getRangeAt(0).toString();, then it seems to work as expected.


  • If Drag select from on the character of "T" and to the right, then it works as expected.
Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core

And there are more problems.

  • Right click context menu 'Search Google for xxxx...' is missing.
  • Right click context menu 'View Selection Source' fails to highlight selected text in source viewer
  • And Ctrl + F does not fetch the selected text.
Ever confirmed: true
Component: DOM: Core & HTML → Selection
Severity: normal → minor
Keywords: testcase-wanted
Priority: -- → P3
Attached file testcase html

Drag selection from 1st line(svg image line) to 2nd line text

Has STR: --- → yes

Regression window:

0b1c98a4a3d4 Andrea Marchesini — Bug 1425440 - Introduce nsINode::RemoveChildNode, r=catalinb
f1035d52904d Andrea Marchesini — Bug 1425440 - Get rid of GetChildAt_Deprecated in nsDocumentEncoder, r=catalinb

Your bunch of patch seems to cause the regression, Can you please look into this?

Flags: needinfo?(amarchesini)
Keywords: regression
Regressed by: 1425440
Has Regression Range: --- → yes

Looks like a regression from this chunk:
We used to do for (j=startOffset; j<endOffset; j++) which would
skip this block if startOffset >= endOffset, but now we enter
the block and iterate until we find the child at startOffset.
It just so happens that startOffset is after the last child
in this case (I think that's a valid offset, but I don't know).
(So we return with a failure in

Component: Selection → Serializers

This fixes it BTW:

-      if (endOffset) {
+      if (startOffset < endOffset) {

mats, do you mind to submit a patch? I can review it.

Flags: needinfo?(amarchesini) → needinfo?(mats)

Sorry, busy, no time to write up testcase and all that...

Flags: needinfo?(mats)

:baku, can you take a look at this one?

Flags: needinfo?(amarchesini)
Assignee: nobody → amarchesini
Flags: needinfo?(amarchesini)
Pushed by
Selection.toString() works correctly when text is selected together with a set of div+svg elements, r=mats

Bulk change to wontfix for 68 (P3+ carryover with needinfo).

You need to log in before you can comment on or make changes to this bug.