Created
November 17, 2023 16:54
-
-
Save germanattanasio/25c7ae684117072331e44371a2bedef8 to your computer and use it in GitHub Desktop.
Check if user agent is a bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
const checkIfUserAgentIsBot = (userAgent) => { | |
const robots = new RegExp(([ | |
/bot/,/spider/,/crawl/, // GENERAL TERMS | |
/APIs-Google/,/AdsBot/,/Googlebot/, // GOOGLE ROBOTS | |
/mediapartners/,/Google Favicon/, | |
/FeedFetcher/,/Google-Read-Aloud/, | |
/DuplexWeb-Google/,/googleweblight/, | |
/bing/,/yandex/,/baidu/,/duckduck/,/yahoo/, // OTHER ENGINES | |
/ecosia/,/ia_archiver/, | |
/checkly/, /headless/, | |
/semrush/, // OTHER | |
]).map((r) => r.source).join("|"),"i"); // BUILD REGEXP + "i" FLAG | |
return robots.test(userAgent); | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment