Since it seems #Google has decided to uni-laterally force through their new anti-#adblock #DRM euphemistically named "Web environment integrity", I decided to add a little bit of code to my website that blanks out the page and displays a protest message with a link to the firefox download page when you visit it from a browser with this DRM feature. Here's the source inside one toot, feel free to copy and put it at the end of your website's <body> before the closing tag:
<script>if(navigator.getEnvironmentIntegrity!==undefined)document.querySelector('body').innerHTML='<h1>Your browser contains Google DRM</h1>"Web Environment Integrity" is a Google euphemism for a DRM that is designed to prevent ad-blocking. In support of an open web, this website does not function with this DRM. Please install a browser such as <a href="https://www.mozilla.org/en-US/firefox/new/">Firefox</a> that respects your freedom and supports ad blockers.';</script>
Download the fastest Firefox ever

Faster page loading, less memory usage and packed with features, the new Firefox is here.

Mozilla
I'm using the API from https://github.com/chromium/chromium/blob/6cf344c02b1bcf07114d512ee389894239416007/chrome/test/data/android/environment_integrity.html#L4 here, if you know a better way to detect the presence of the feature, please go ahead and tell me :)
chromium/chrome/test/data/android/environment_integrity.html at 6cf344c02b1bcf07114d512ee389894239416007 · chromium/chromium

The official GitHub mirror of the Chromium source. Contribute to chromium/chromium development by creating an account on GitHub.

GitHub

@jaseg JavaScript dev for a living here, that's the best way to do feature detection, yeah.

You may want to consider making a new node in code, clearing body and appending it inside body as opposed to slamming innerHTML though 🤷‍♂️

@guades I apologize for the innerHTML slam. I know better, but I wanted to prioritize the protest message under my instance's 500 character toot limit 😅

@jaseg thankfully my GotoSocial does not have such a puny limit. I found also out (the hard way) that you have to clear all CSS, otherwise the new content may be illegible.

New approach:

<script type="text/javascript"><!--//--><![CDATA[//><!-- document.addEventListener("DOMContentLoaded", function () { /* do not run if browser lacks the antifeature */ if (navigator.getEnvironmentIntegrity === undefined) return; /* disable all CSS */ for (let elt of document.getElementsByTagName("link")) elt.disabled = true; /* replace body content */ var r1 = document.createElement("h1"); r1.appendChild(document.createTextNode("Your browser contains Google DRM!")); var r2 = document.createElement("p"); r2.innerHTML = '“Web Environment Integrity” is a Google euphemism for DRM (digital restrictions management) that is designed to prevent ad-blocking and allow only browsers authorised by Google (as opposed to e.g. browsers on hobbyist or aftermarket operating systems). In support of an open web, this website does not function with browsers that utilise this kind of DRM. Please install a webbrowser such as <a href="https://invisible-island.net/lynx/lynx.html"><tt>lynx</tt></a> or <a href="https://www.mozilla.org/en-US/firefox/new/">Firefox</a> that better respects everyone’s freedom and supports ad blockers.'; document.getElementsByTagName('body')[0].replaceChildren(r1, r2); }, false); //--><!]]></script>

Of course I could do the whole creating of text and element nodes for r2 as well but I figured it’s not that bad for a newly created node tree. If it is @guades please do tell me, I’m more of an assembly, C and Korn Shell developer.

(I put the whole stuff in front of </body> and reversed the conditional in the forth line to test it.)

That being said (I used the OP test conditional above), should it not be…

if (typeof(navigator.getEnvironmentIntegrity) === "undefined")

… because otherwise you can get error messages for use of undefined variables? I think I ran into that once.

@mirabilos @jaseg @guades Apache mod_rewrite is (as usual) your friend. Search down this page for 'Browser Dependent Content':

https://httpd.apache.org/docs/2.4/rewrite/remapping.html

Redirecting and Remapping with mod_rewrite - Apache HTTP Server Version 2.4

@simon_brooke @jaseg @guades huh no, then I would have to duplicate all files. I’d just rather write the JS in a way it doesn’t break other browsers. With usefulJS I think I succeeded (I did test it in Opera 9, and stuff works; I don’t have any need for things to work on old MSIE versions, just not break beyond expectation there).
@mirabilos @jaseg @guades Only one. The one that explains how to download a DRM-free browser.
@simon_brooke @jaseg @guades no, because you have to switch that on the js level depending on whether the browser has the attestation extension or not

@mirabilos @jaseg @guades No, you can do it with mod_rewrite, on the user agent string, which contains the browser version.

https://www.whatismybrowser.com/guides/the-latest-user-agent/chrome

@simon_brooke @jaseg @guades no, because comparing by versions is not the correct way to detect this, neither complete nor safe from false positives
@simon_brooke @jaseg @guades what you could do is to change the location in the js instead, sure. That’d allow for using the site’s proper style, even. Not a simple drop-in solution, but not bad either.

@mirabilos @jaseg @guades That may be what you do.

You do you.