As an alternative, all browsers the traditional scrolling to named element using a URL fragment, e.g.
https://en.wikipedia.org/wiki/URI#Syntax goes to the "Syntax" section of the page. While the reason of text fragments it to allow for similar linking where there isn't an element with an id,
most pages with non-changing text tend also to have non-changing layout and element ids.
If you generate links that include and depend on #:~:text= to make sense, accept that it will confuse users whose browsers do not support it. They will be linked to the top of the document and no text will be highlighted. Consider not only linking, but also quoting what you wanted to be highlighted, e.g.
John says <a href="https://example.com/#:~:text=I%20dislike%20this">he dislikes it</a>:
<blockquote cite="https://example.com/">
Down with this sort of thing. <em>I dislike this</em> and can't abide it.
</blockquote>