How to detect Adblock on my website?

If you enter to that site and your browser has some kind of adblock software enabled, then the site instead of showing the actual ads shows a little banner telling the users that the ad revenue is used for hosting the project and they should consider turning Adblock off.

This one works good

if there’s an adBlocker it will alert you

<!DOCTYPE html>
<html>
<head>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>

</head>
<body>

<script>
checkAdBlocker();

function checkAdBlocker() {
try {
fetch(
new Request(“https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js”, {
method: ‘HEAD’,
mode: ‘no-cors’
})).catch(error => {
showNotification()
});
} catch (e) {
// Request failed, likely due to ad blocker
showNotification()
}
}

function showNotification() {
alert(“Please disable adBlocker”)
}
</script>

</body>
</html>