This is a problem with Firefox (24), not with rangy but I thought people using rangy might like to know (so as to avoid the few hours I spent tracking down this bug). The bug has been reported here:
https://bugzilla.mozilla.org/show_bug.cgi?id=921444This bug would manifest while using rangy if you ever use sel.addRange(range, true) to add a range "backwards". That's something I do in my software when a user actually selects text backwards. (I can't let the browser handle it itself because contenteditable is pretty much a broken feature, the way browsers handle input methods, etc.) When addRange is called to add a range backwards and there is an extend() method available on selections, then rangy uses the extend() method, which
may trigger the issue. And actually, if you do use extend() yourself in your own code, outside of rangy, (which I do) then you can get that error there too.
This problem happens
if at the time extend() is called the element which contains the selection to be extended
is not the same as the element which is currently focused. On Firefox, for some reason, if the focus is in element X, and JS code sets the selection to be in element Y's text and Y is focusable, then the focus
remains in X. On Chrome, setting the selection to Y's text also focuses Y.
The workaround is to manually move the focus before extending. I'm not reporting it as a rangy issue since it is not a rangy bug.