Detect Search Crawlers via JavaScript

前端 未结 5 1383
天命终不由人
天命终不由人 2020-12-12 23:55

I am wondering how would I go abouts in detecting search crawlers? The reason I ask is because I want to suppress certain JavaScript calls if the user agent is a bot.

<
5条回答
  •  感动是毒
    2020-12-13 00:33

    isTrusted property could help you.

    The isTrusted read-only property of the Event interface is a Boolean that is true when the event was generated by a user action, and false when the event was created or modified by a script or dispatched via EventTarget.dispatchEvent().

    eg:

    isCrawler() {
      return event.isTrusted;
    }
    

    ⚠ Note that IE isn't compatible.

    Read more from doc: https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted

提交回复
热议问题