Get user selected text of google docs in 2024?

Many workarounds have been created but then deprecated as Google updates how Google docs work.

I know this has been talked about a lot, but no one provided a solution that still works in 2024.

It’s obviously possible because Grammarly exists, but it seems like a black box right now?

Obviously I can make a Google docs add-on, but my goal is to have a Chrome extension that works on any website, not just Google docs.