How to highlight all instances of a string using Chrome's Text Fragments feature?

Viewed 266

I recently found out about the new Chrome feature called "Text Fragments" that allows links to point directly to a certain text inside an URL and have it highlighted. For example:

https://www.nytimes.com/#:~:text=Magazine

But if I point to a work that appears multiple times, only the first instance gets highlighted.

Is there any way that I can ask it to highlight all occurrences of a given string?

1 Answers

From what I can tell, the spec only allows for highlighting the first instance found on a page. You can specify multiple strings, but they'll all always match to the first occurrence (as of Chrome 83).

The best I can think of is expanding the matching region such that each occurrence is a unique substring. For instance, on this page one could use something like:

#:~:text=highlight%20all&text=highlighted&text=it%20to%20highlight&text=for%20highlighting

And generate these URLs via javascript.

Related