SUI-Components / sui

Monorepo for SUI (Simple User Interface) packages.
169 stars 33 forks source link

feat(packages/sui-js): add method to check if user agent is a bot #1775

Closed ivanmlaborda closed 2 months ago

ivanmlaborda commented 2 months ago

Check user agents to detect bots

Description

checkLegitimateCrawler method can detect if the passed user agent is one of the following legitimate bots [
'googlebot', 'google-structured-data-testing-tool', 'bingbot', 'linkedinbot', 'mediapartners-google', 'debugbear' ]

Example

const BOT_USER_AGENT = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'

checkUserAgentIsBot(BOT_USER_AGENT) // returns true

jordevo commented 2 months ago

we have a ua-parser context in this package... wouldn't it make sense to keep this checkUserAgentIsBot under a common folder, since they both are related to user agents? 🤔

https://github.com/SUI-Components/sui/blob/master/packages/sui-js/src/ua-parser/index.js

ivanmlaborda commented 2 months ago

we have a ua-parser context in this package... wouldn't it make sense to keep this checkUserAgentIsBot under a common folder, since they both are related to user agents? 🤔

https://github.com/SUI-Components/sui/blob/master/packages/sui-js/src/ua-parser/index.js

Before sending this PR, I was thinking about it and didn't see a clear relation between UA parsing and business logic to define legitimate bots. I don't know.