The Range instance returned by various Selection methods – most commonly sindow.getSelection().getRangeAt(0) – does not provide enough information to determine the total offset of the caret (or selection start/end). Here’s how:

POC: https://jsfiddle.net/moagrius/L1pwhmae/