[submodule:helpers] Add new method isAIBot(): detect AI bots

This commit is contained in:
Faisal Salman
2024-11-16 22:14:14 +07:00
parent 5b375b90d5
commit 70b3003344
5 changed files with 102 additions and 6 deletions

View File

@@ -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', () => {