Finding the currently focused DOM element is trivial in modern CSS, using the
const focusedElement = document.activeElement; // `focusedElement` is the currently focused element
Note that focusable elements vary depending on browser and operating system. Additionally, you should remember that focus and selection (i.e. content highlighting) are not the same thing.