New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

es6-crawler-detect

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es6-crawler-detect

This is an ES6 adaptation of the original PHP library CrawlerDetect, this library will help you detect bots/crawlers/spiders vie the useragent.

Source
npmnpm
Version
4.0.1
Version published
Weekly downloads
13K
-23%
Maintainers
1
Weekly downloads
 
Created
Source

Crawler Detect



crawlerdetect.io

DeepScan grade npm version contributions welcome

About

This Library is an ES6 version of the original PHP class @CrawlerDetect, it helps you detect bots/crawlers and spiders only by scanning the user-agent string or from the global request.headers.

Installation

npm install es6-crawler-detect

Usage

ECMAScript 6 (ES6)

'use strict';

const express = require('express')
const { Crawler, middleware } = require('es6-crawler-detect')

const app = express()

app.get('your/route', function async (request, response) {
  // create a new Crawler instance
  var CrawlerDetector = new Crawler(request)
  
  // check the current visitor's useragent
  if ( CrawlerDetector.isCrawler() )
  {
    // true if crawler user agent detected
  }
  
  // or check a user agent string
  if ( CrawlerDetector.isCrawler('Mozilla/5.0 (compatible; Sosospider/2.0; +http://help.soso.com/webspider.htm)') )
  {
    // true if crawler user agent detected
  }
  
  // Output the name of the bot that matched (if any)
  response.send(CrawlerDetector.getMatches())
})

/**
 * Or by using the middleware
*/
app.use(middleware((request, reponse) => {
  // do something here
  // e.g. console.log(request.body)
  // e.g. return response.status(403).send('Forbidden')
}))

app.get('/crawler', function async (request, response) {
  // or check a user agent string
  request.Crawler.isCrawler('Mozilla/5.0 (compatible; Sosospider/2.0; +http://help.soso.com/webspider.htm)')
  
  // Output the name of the bot that matched (if any)
  response.send(request.Crawler.getMatches())
})

TypeScript

import { Crawler, middleware } from 'es6-crawler-detect'

const CrawlerDetector = new Crawler()

// check the current visitor's useragent
if ( CrawlerDetector.isCrawler() )
{
  // true if crawler user agent detected
}

// or check a user agent string
if ( CrawlerDetector.isCrawler('Mozilla/5.0 (compatible; Sosospider/2.0; +http://help.soso.com/webspider.htm)') )
{
  // true if crawler user agent detected
}

// Output the name of the bot that matched (if any)
console.log(CrawlerDetector.getMatches())

/**
 * Or by using the middleware
*/
middleware((request, reponse) => {
  // do something here
  // e.g. console.log(request.body)
  // e.g. return response.status(403).send('Forbidden')
})

Contributing

If you find a bot/spider/crawler user agent that CrawlerDetect fails to detect, please submit a pull request with the regex pattern added to the data array in ./crawler/crawlers.ts.

Keywords

es6-javascript

FAQs

Package last updated on 16 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts