Generally speaking it seems that the textUnderElement ought to contain the same kind of whitespace-collapsing logic that the normal rendering code does. This could be done by using the TextIterator instead of walking the nodes and concatenating them all. Not sure what bug it will cause that this just appends the DOM, but I suspect it will cause problems, especially when there are
elements with "display: none" or "visibility: hidden" involved.
we decided against this because it would not allow us to include the alt text of an image when getting the textUnderElement