Mastodon Kuan0: Chrome highlights text on webpages: how to disable

Sunday 23 August 2020

Chrome highlights text on webpages: how to disable

This blog explains how to stop Chrome's highlighting of text on some webpages you visit after clicking on Google search results snippets. 

The problem: Chrome now scrolls directly to the highlighted text ("text fragments", meant to reflect your search terms) on the webpage in question. It also mangles the URL in the browser so that the web address has, appended to it:
#:~:text=whateverTextFragmentIsToBeHighlightedWhichCanBeVeryLong

For anyone who's managed to escape this new feature, here's a direct example. (Apparently it also does this in Apple's Safari.) Not everyone wants that behaviour in their browser and can even find it annoying and unhelpful. This new Chrome feature was introduced by Google in early June 2020. Websites can opt out, but it's much more difficult for Chrome end users to disable it.

To prevent this happening via Chrome flags is no longer possible. Most people may not be able (or want) to set enterprise policies or mess with their registry (which even stopped Chrome working for one person), or install the Redirector extension with more fiddling.

So, here's my own relatively easy fix, which you can use to change the webpage back to what it should be, rather than preventing or getting rid of the new feature. My solution to this issue:

  • "Reverts" you to the webpage you were trying to view, without highlighting the text fragment or scrolling to it.
  • Cleans up the URL in the address bar too, removing the # and all the stuff after it.
  • (Optional - even copies the "clean" URL to your clipboard for easy sharing.)
It involves setting up a new bookmarklet or favelet with some Javascript, that you can just click (or use a hotkey to access), to sort out the issue quickly. If that description fazes non-coders, not to worry, here's a very simple step by step:

 

Solution to remove unwanted text highlighting

  1. Make your bookmarks bar visible in Chrome if it's not already (click top right up arrow > Bookmarks > Show Bookmarks, or press Ctrl-Shift-b).
  2. Bookmark any webpage you like (e.g. Ctrl-d and Enter), but drag it so it's visible in the bar.
  3. Rightclick the new bookmark in the bar, select Edit.
  4. In the Name box, change it to e.g. Cleanup, or even just 1 (I'll explain the latter later), ideally starting with a letter which your existing bookmarks don't start with.
  5. In the URL box, clear what's there, and copy and paste the following text in there instead, exactly as is (don't add spaces etc.), then click Save:
    javascript:var url=window.location.href; cleanurl=url.split('#')[0]; window.location.replace(cleanurl); 
  6. In future, if you find yourself on a webpage with highlighted text fragments and the long URL after clicking on Google search results, to clean it up just:
    1. Click that new bookmark in the bookmarks bar, or
    2. (For those who like keyboard shortcuts) Press Alt-e then b then 1 (or whatever was the first letter of the new bookmark's name) then, if necessary, Enter - which has the same effect as clicking it.
  7. Optional: if you also want to be able to copy the clean URL automatically to your clipboard for pasting into an email etc. then, in step 5 above, instead of pasting what was shown there just paste the following exactly as is:
    javascript:var url=window.location.href; cleanurl=url.split('#')[0]; var input=document.body.appendChild(document.createElement("input")); input.value=cleanurl; input.focus(); input.select();   document.execCommand('copy'); input.parentNode.removeChild(input); window.location.replace(cleanurl); 
I hope that's helpful.