I use this code How can I position an element next to user text selection? to get the position of the selected text, but it doesn\'t work for the selected text inside an input.
You can use getSelection api.
After selection a text run below code in console.
var selection = window.getSelection()
var baseOffset = selection.baseOffset
var length = selection.focusOffset -selection.baseOffset
var text = selection.focusNode.data.splice(baseOffset, length)