mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-30 17:27:44 +03:00
[submodule:helpers] Add new method isAIBot()
: detect AI bots
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const assert = require('assert');
|
||||
const { UAParser } = require('../src/main/ua-parser');
|
||||
const { getDeviceVendor, isAppleSilicon, isBot, isChromeFamily } = require('../src/helpers/ua-parser-helpers');
|
||||
const { getDeviceVendor, isAppleSilicon, isAIBot, isBot, isChromeFamily } = require('../src/helpers/ua-parser-helpers');
|
||||
const { Bots, Emails } = require('../src/extensions/ua-parser-extensions');
|
||||
|
||||
describe('getDeviceVendor', () => {
|
||||
@@ -34,6 +34,20 @@ describe('isAppleSilicon', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('isAIBot', () => {
|
||||
it('Can detect AI Bots', () => {
|
||||
|
||||
const claudeBot = 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)';
|
||||
const firefox = 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/111.0';
|
||||
const searchGPT = 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko); compatible; OAI-SearchBot/1.0; +https://openai.com/searchbot';
|
||||
|
||||
assert.equal(isAIBot(UAParser(claudeBot, Bots)), true);
|
||||
assert.equal(isAIBot(claudeBot), true);
|
||||
assert.equal(isAIBot(firefox), false);
|
||||
assert.equal(isAIBot(searchGPT), true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isBot', () => {
|
||||
it('Can detect Bots', () => {
|
||||
|
||||
|
Reference in New Issue
Block a user