getSelection

Returns an object representing the current selection of the document that is loaded into the object displaying a webpage.

MDN Reference