Window: getSelection() method - Web APIs | MDN
The getSelection() method of the Window interface returns the Selection object associated with the window's document, representing the range of text selected by the user or the current position of the caret.