@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 🤷♂️
@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':
@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
@mirabilos @jaseg @guades That may be what you do.
You do you.