From a1538504cf8dff08841fae3b7ab6c23b872adb2e Mon Sep 17 00:00:00 2001 From: Leo Developer Date: Sat, 26 Aug 2023 12:17:24 +0200 Subject: [PATCH 01/13] make it better see the linked issue/pr for more information on motivation --- src/api.ts | 63 +++++++++++++++++++++++++++++++++++++ src/detector.ts | 84 +++---------------------------------------------- src/index.ts | 5 +++ 3 files changed, 72 insertions(+), 80 deletions(-) create mode 100644 src/api.ts diff --git a/src/api.ts b/src/api.ts new file mode 100644 index 00000000..fe11d87f --- /dev/null +++ b/src/api.ts @@ -0,0 +1,63 @@ +import { detectors } from './detectors' +import { sources } from './sources' +import { BotdError, BotDetectionResult, BotKind, Component, ComponentDict, DetectionDict, State } from './types' + +export function detect(components: ComponentDict): [DetectionDict, BotDetectionResult] { + const detections = {} as DetectionDict + let finalDetection: BotDetectionResult = { + bot: false, + } + + for (const detectorName in detectors) { + const detector = detectors[detectorName as keyof typeof detectors] + const detectorRes = detector(components) + + let detection: BotDetectionResult = { bot: false } + + if (typeof detectorRes === 'string') { + detection = { bot: true, botKind: detectorRes } + } else if (detectorRes) { + detection = { bot: true, botKind: BotKind.Unknown } + } + + detections[detectorName as keyof typeof detectors] = detection + + if (detection.bot) { + finalDetection = detection + } + } + + return [detections, finalDetection] +} + +export async function collect(): Promise { + const components = {} as ComponentDict + const sourcesKeys = Object.keys(sources) as (keyof typeof sources)[] + + await Promise.all( + sourcesKeys.map(async (sourceKey) => { + const res = sources[sourceKey] + + try { + components[sourceKey] = ({ + value: await res(), + state: State.Success, + } as Component) as any + } catch (error) { + if (error instanceof BotdError) { + components[sourceKey] = { + state: error.state, + error: `${error.name}: ${error.message}`, + } + } else { + components[sourceKey] = { + state: State.UnexpectedBehaviour, + error: error instanceof Error ? `${error.name}: ${error.message}` : String(error), + } + } + } + }), + ) + + return components +} diff --git a/src/detector.ts b/src/detector.ts index 6d5b476e..a63f45fc 100644 --- a/src/detector.ts +++ b/src/detector.ts @@ -1,15 +1,5 @@ -import { detectors } from './detectors' -import { sources } from './sources' -import { - BotdError, - BotDetectionResult, - BotDetectorInterface, - BotKind, - Component, - ComponentDict, - DetectionDict, - State, -} from './types' +import { BotDetectionResult, BotDetectorInterface, ComponentDict, DetectionDict } from './types' +import { collect, detect } from './api' /** * Class representing a bot detector. @@ -30,16 +20,6 @@ export default class BotDetector implements BotDetectorInterface { return this.detections } - // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types - protected getSources() { - return sources - } - - // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types - protected getDetectors() { - return detectors - } - /** * @inheritdoc */ @@ -48,35 +28,9 @@ export default class BotDetector implements BotDetectorInterface { throw new Error("BotDetector.detect can't be called before BotDetector.collect") } - const components = this.components - const detectors = this.getDetectors() - - const detections = {} as DetectionDict - let finalDetection: BotDetectionResult = { - bot: false, - } - - for (const detectorName in detectors) { - const detector = detectors[detectorName as keyof typeof detectors] - const detectorRes = detector(components) - - let detection: BotDetectionResult = { bot: false } - - if (typeof detectorRes === 'string') { - detection = { bot: true, botKind: detectorRes } - } else if (detectorRes) { - detection = { bot: true, botKind: BotKind.Unknown } - } - - detections[detectorName as keyof typeof detectors] = detection - - if (detection.bot) { - finalDetection = detection - } - } + const [detections, finalDetection] = detect(this.components) this.detections = detections - return finalDetection } @@ -84,37 +38,7 @@ export default class BotDetector implements BotDetectorInterface { * @inheritdoc */ public async collect(): Promise { - const sources = this.getSources() - const components = {} as ComponentDict - - const sourcesKeys = Object.keys(sources) as (keyof typeof sources)[] - - await Promise.all( - sourcesKeys.map(async (sourceKey) => { - const res = sources[sourceKey] - - try { - components[sourceKey] = ({ - value: await res(), - state: State.Success, - } as Component) as any - } catch (error) { - if (error instanceof BotdError) { - components[sourceKey] = { - state: error.state, - error: `${error.name}: ${error.message}`, - } - } else { - components[sourceKey] = { - state: State.UnexpectedBehaviour, - error: error instanceof Error ? `${error.name}: ${error.message}` : String(error), - } - } - } - }), - ) - - this.components = components + this.components = await collect() return this.components } } diff --git a/src/index.ts b/src/index.ts index e3b9bbcf..6b08715b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,9 @@ import { version } from '../package.json' import BotDetector from './detector' import { sources, WindowSizePayload, ProcessPayload, DistinctivePropertiesPayload } from './sources' +import { detectors } from './detectors' import { BotdError, BotDetectorInterface, BotKind, BotDetectionResult } from './types' +import { collect, detect } from './api' /** * Options for BotD loading @@ -48,6 +50,9 @@ export default { load } /** Not documented, out of Semantic Versioning, usage is at your own risk */ export { sources, + detectors, + collect, + detect, BotdError, WindowSizePayload, ProcessPayload, From 1e5294a82bd2da6b9fe3326d3ab79a68e62c8c04 Mon Sep 17 00:00:00 2001 From: Leo Developer Date: Mon, 11 Sep 2023 12:50:48 +0200 Subject: [PATCH 02/13] add collect and detectors arguments to collect and detect --- src/api.ts | 25 ++++++++++++++++++------- src/detector.ts | 5 +++-- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/api.ts b/src/api.ts index fe11d87f..adf0af86 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,9 +1,20 @@ -import { detectors } from './detectors' -import { sources } from './sources' -import { BotdError, BotDetectionResult, BotKind, Component, ComponentDict, DetectionDict, State } from './types' +import { + AbstractDetectorDict, + AbstractSourceDict, + BotdError, + BotDetectionResult, + BotKind, + Component, + ComponentDict, + DetectionDict, + State, +} from './types' -export function detect(components: ComponentDict): [DetectionDict, BotDetectionResult] { - const detections = {} as DetectionDict +export function detect( + components: ComponentDict, + detectors: T, +): [DetectionDict, BotDetectionResult] { + const detections = {} as DetectionDict let finalDetection: BotDetectionResult = { bot: false, } @@ -30,8 +41,8 @@ export function detect(components: ComponentDict): [DetectionDict, BotDetectionR return [detections, finalDetection] } -export async function collect(): Promise { - const components = {} as ComponentDict +export async function collect(sources: T): Promise> { + const components = {} as ComponentDict const sourcesKeys = Object.keys(sources) as (keyof typeof sources)[] await Promise.all( diff --git a/src/detector.ts b/src/detector.ts index a63f45fc..65ba891f 100644 --- a/src/detector.ts +++ b/src/detector.ts @@ -1,5 +1,6 @@ import { BotDetectionResult, BotDetectorInterface, ComponentDict, DetectionDict } from './types' import { collect, detect } from './api' +import { detectors, sources } from '.' /** * Class representing a bot detector. @@ -28,7 +29,7 @@ export default class BotDetector implements BotDetectorInterface { throw new Error("BotDetector.detect can't be called before BotDetector.collect") } - const [detections, finalDetection] = detect(this.components) + const [detections, finalDetection] = detect(this.components, detectors) this.detections = detections return finalDetection @@ -38,7 +39,7 @@ export default class BotDetector implements BotDetectorInterface { * @inheritdoc */ public async collect(): Promise { - this.components = await collect() + this.components = await collect(sources) return this.components } } From 89004ed2dc5d046aaea9345990f408c374b5935f Mon Sep 17 00:00:00 2001 From: Leo Developer Date: Mon, 11 Sep 2023 13:17:43 +0200 Subject: [PATCH 03/13] collect browser info --- src/sources/browser.test.ts | 27 +++++++++++++++++++++++++++ src/sources/browser.ts | 20 ++++++++++++++++++++ src/sources/index.ts | 2 ++ 3 files changed, 49 insertions(+) create mode 100644 src/sources/browser.test.ts create mode 100644 src/sources/browser.ts diff --git a/src/sources/browser.test.ts b/src/sources/browser.test.ts new file mode 100644 index 00000000..fa6e39d4 --- /dev/null +++ b/src/sources/browser.test.ts @@ -0,0 +1,27 @@ +import { isChromium, isGecko, isMobile, isWebKit } from '../../tests/utils' +import { BrowserEngineKind, BrowserKind } from '../types' +import getBrowserInformation from './browser' + +describe('Sources', () => { + describe('browser', () => { + it('returns an expected value', () => { + const value = getBrowserInformation() + + if (isChromium()) { + expect(value.browserEngineKind).toBe(BrowserEngineKind.Chromium) + expect(value.browserKind).toBe(BrowserKind.Chrome) + expect(value.isAndroid).toBe(isMobile()) + } + if (isGecko()) { + expect(value.browserEngineKind).toBe(BrowserEngineKind.Gecko) + expect(value.browserKind).toBe(BrowserKind.Firefox) + expect(value.isAndroid).toBeFalse() + } + if (isWebKit()) { + expect(value.browserEngineKind).toBe(BrowserEngineKind.Webkit) + expect(value.browserKind).toBe(BrowserKind.Safari) + expect(value.isAndroid).toBeFalse() + } + }) + }) +}) diff --git a/src/sources/browser.ts b/src/sources/browser.ts new file mode 100644 index 00000000..94e8bcc3 --- /dev/null +++ b/src/sources/browser.ts @@ -0,0 +1,20 @@ +import { BrowserEngineKind, BrowserKind } from '../types' +import { getBrowserEngineKind, getBrowserKind, getDocumentFocus, isAndroid, isDesktopSafari } from '../utils/browser' + +export default function getBrowserInformation(): BrowserInformation { + return { + browserEngineKind: getBrowserEngineKind(), + browserKind: getBrowserKind(), + isAndroid: isAndroid(), + isDesktopSafari: isDesktopSafari(), + documentFocus: getDocumentFocus(), + } +} + +interface BrowserInformation { + browserEngineKind: BrowserEngineKind + browserKind: BrowserKind + isAndroid: boolean + isDesktopSafari: boolean + documentFocus: boolean +} diff --git a/src/sources/index.ts b/src/sources/index.ts index 8db41ca0..0292d6da 100644 --- a/src/sources/index.ts +++ b/src/sources/index.ts @@ -1,4 +1,5 @@ import getAppVersion from './app_version' +import getBrowserInformation from './browser' import getDocumentElementKeys from './document_element_keys' import getErrorTrace from './error_trace' import getEvalLength from './eval_length' @@ -21,6 +22,7 @@ import checkDistinctiveProperties, { DistinctivePropertiesPayload } from './dist export const sources = { userAgent: getUserAgent, appVersion: getAppVersion, + browser: getBrowserInformation, rtt: getRTT, windowSize: getWindowSize, pluginsLength: getPluginsLength, From 6fe07cb6f2ba1ec7a6ec86da60ea9fc2b6c441e1 Mon Sep 17 00:00:00 2001 From: Leo Developer Date: Mon, 11 Sep 2023 13:23:20 +0200 Subject: [PATCH 04/13] remove dependence on browser apis --- src/detectors/eval_length.ts | 8 ++++---- src/detectors/notification_permissions.ts | 7 ++++--- src/detectors/plugins_inconsistency.ts | 9 +++++---- src/detectors/product_sub.ts | 4 +--- src/detectors/rtt.ts | 5 ++--- src/detectors/window_size.ts | 5 ++--- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/detectors/eval_length.ts b/src/detectors/eval_length.ts index a1746e71..3475ad33 100644 --- a/src/detectors/eval_length.ts +++ b/src/detectors/eval_length.ts @@ -1,12 +1,12 @@ import { arrayIncludes } from '../utils/ponyfills' import { BrowserEngineKind, BrowserKind, ComponentDict, DetectorResponse, State } from '../types' -import { getBrowserEngineKind, getBrowserKind } from '../utils/browser' -export function detectEvalLengthInconsistency({ evalLength }: ComponentDict): DetectorResponse { +export function detectEvalLengthInconsistency({ + evalLength, + browser: { browserKind: browser, BrowserEngineKind: browserEngine }, +}: ComponentDict): DetectorResponse { if (evalLength.state !== State.Success) return const length = evalLength.value - const browser = getBrowserKind() - const browserEngine = getBrowserEngineKind() return ( (length === 37 && !arrayIncludes([BrowserEngineKind.Webkit, BrowserEngineKind.Gecko], browserEngine)) || (length === 39 && !arrayIncludes([BrowserKind.IE], browser)) || diff --git a/src/detectors/notification_permissions.ts b/src/detectors/notification_permissions.ts index d6a6d2de..5115cd26 100644 --- a/src/detectors/notification_permissions.ts +++ b/src/detectors/notification_permissions.ts @@ -1,8 +1,9 @@ import { BotKind, BrowserKind, ComponentDict, DetectorResponse, State } from '../types' -import { getBrowserKind } from '../utils/browser' -export function detectNotificationPermissions({ notificationPermissions }: ComponentDict): DetectorResponse { - const browserKind = getBrowserKind() +export function detectNotificationPermissions({ + notificationPermissions, + browser: { browserKind }, +}: ComponentDict): DetectorResponse { if (browserKind !== BrowserKind.Chrome) return false if (notificationPermissions.state === State.Success && notificationPermissions.value) { diff --git a/src/detectors/plugins_inconsistency.ts b/src/detectors/plugins_inconsistency.ts index 203b9f07..55439c24 100644 --- a/src/detectors/plugins_inconsistency.ts +++ b/src/detectors/plugins_inconsistency.ts @@ -1,9 +1,10 @@ import { BotKind, BrowserKind, ComponentDict, DetectorResponse, State } from '../types' -import { getBrowserKind, isAndroid } from '../utils/browser' -export function detectPluginsLengthInconsistency({ pluginsLength }: ComponentDict): DetectorResponse { +export function detectPluginsLengthInconsistency({ + pluginsLength, + browser: { browserKind, isAndroid }, +}: ComponentDict): DetectorResponse { if (pluginsLength.state !== State.Success) return - const browserKind = getBrowserKind() - if (browserKind !== BrowserKind.Chrome || isAndroid()) return + if (browserKind !== BrowserKind.Chrome || isAndroid) return if (pluginsLength.value === 0) return BotKind.HeadlessChrome } diff --git a/src/detectors/product_sub.ts b/src/detectors/product_sub.ts index 238cc0dd..89410b0f 100644 --- a/src/detectors/product_sub.ts +++ b/src/detectors/product_sub.ts @@ -1,9 +1,7 @@ import { BotKind, BrowserKind, ComponentDict, DetectorResponse, State } from '../types' -import { getBrowserKind } from '../utils/browser' -export function detectProductSub({ productSub }: ComponentDict): DetectorResponse { +export function detectProductSub({ productSub, browser: { browserKind } }: ComponentDict): DetectorResponse { if (productSub.state !== State.Success) return false - const browserKind = getBrowserKind() if ( (browserKind === BrowserKind.Chrome || browserKind === BrowserKind.Safari || diff --git a/src/detectors/rtt.ts b/src/detectors/rtt.ts index 6195cbe2..d0115ea6 100644 --- a/src/detectors/rtt.ts +++ b/src/detectors/rtt.ts @@ -1,9 +1,8 @@ import { BotKind, ComponentDict, DetectorResponse, State } from '../types' -import { isAndroid } from '../utils/browser' -export function detectRTT({ rtt }: ComponentDict): DetectorResponse { +export function detectRTT({ rtt, browser: { isAndroid } }: ComponentDict): DetectorResponse { if (rtt.state !== State.Success) return // Rtt is 0 on android webview - if (isAndroid()) return + if (isAndroid) return if (rtt.value === 0) return BotKind.HeadlessChrome } diff --git a/src/detectors/window_size.ts b/src/detectors/window_size.ts index 2a08d155..b68de7c9 100644 --- a/src/detectors/window_size.ts +++ b/src/detectors/window_size.ts @@ -1,10 +1,9 @@ import { BotKind, ComponentDict, DetectorResponse, State } from '../types' -import { getDocumentFocus } from '../utils/browser' -export function detectWindowSize({ windowSize }: ComponentDict): DetectorResponse { +export function detectWindowSize({ windowSize, browser: { documentFocus } }: ComponentDict): DetectorResponse { if (windowSize.state !== State.Success) return false const { outerWidth, outerHeight } = windowSize.value // When a page is opened in a new tab without focusing it right away, the window outer size is 0x0 - if (!getDocumentFocus()) return + if (!documentFocus) return if (outerWidth === 0 && outerHeight === 0) return BotKind.HeadlessChrome } From 036e711f5642615bdc61c9e301efc01cd8e2fd0a Mon Sep 17 00:00:00 2001 From: Leo Developer Date: Mon, 11 Sep 2023 13:25:24 +0200 Subject: [PATCH 05/13] not used --- src/sources/browser.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/sources/browser.ts b/src/sources/browser.ts index 94e8bcc3..0749e492 100644 --- a/src/sources/browser.ts +++ b/src/sources/browser.ts @@ -1,12 +1,11 @@ import { BrowserEngineKind, BrowserKind } from '../types' -import { getBrowserEngineKind, getBrowserKind, getDocumentFocus, isAndroid, isDesktopSafari } from '../utils/browser' +import { getBrowserEngineKind, getBrowserKind, getDocumentFocus, isAndroid } from '../utils/browser' export default function getBrowserInformation(): BrowserInformation { return { browserEngineKind: getBrowserEngineKind(), browserKind: getBrowserKind(), isAndroid: isAndroid(), - isDesktopSafari: isDesktopSafari(), documentFocus: getDocumentFocus(), } } @@ -15,6 +14,5 @@ interface BrowserInformation { browserEngineKind: BrowserEngineKind browserKind: BrowserKind isAndroid: boolean - isDesktopSafari: boolean documentFocus: boolean } From b16e8f58c03cfc3d79b477005b84ff947fd026d5 Mon Sep 17 00:00:00 2001 From: Leo Developer Date: Mon, 11 Sep 2023 13:31:43 +0200 Subject: [PATCH 06/13] fix wrong access --- src/detectors/eval_length.ts | 12 +++++++----- src/detectors/notification_permissions.ts | 4 ++-- src/detectors/plugins_inconsistency.ts | 5 +++-- src/detectors/product_sub.ts | 5 +++-- src/detectors/rtt.ts | 5 +++-- src/detectors/window_size.ts | 5 +++-- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/detectors/eval_length.ts b/src/detectors/eval_length.ts index 3475ad33..2fee19ca 100644 --- a/src/detectors/eval_length.ts +++ b/src/detectors/eval_length.ts @@ -3,13 +3,15 @@ import { BrowserEngineKind, BrowserKind, ComponentDict, DetectorResponse, State export function detectEvalLengthInconsistency({ evalLength, - browser: { browserKind: browser, BrowserEngineKind: browserEngine }, + browser: browserComponent }: ComponentDict): DetectorResponse { - if (evalLength.state !== State.Success) return + if (evalLength.state !== State.Success || browserComponent.state !== State.Success) return + + const { browserKind, browserEngineKind } = browserComponent.value const length = evalLength.value return ( - (length === 37 && !arrayIncludes([BrowserEngineKind.Webkit, BrowserEngineKind.Gecko], browserEngine)) || - (length === 39 && !arrayIncludes([BrowserKind.IE], browser)) || - (length === 33 && !arrayIncludes([BrowserEngineKind.Chromium], browserEngine)) + (length === 37 && !arrayIncludes([BrowserEngineKind.Webkit, BrowserEngineKind.Gecko], browserEngineKind)) || + (length === 39 && !arrayIncludes([BrowserKind.IE], browserKind)) || + (length === 33 && !arrayIncludes([BrowserEngineKind.Chromium], browserEngineKind)) ) } diff --git a/src/detectors/notification_permissions.ts b/src/detectors/notification_permissions.ts index 5115cd26..5f84bf92 100644 --- a/src/detectors/notification_permissions.ts +++ b/src/detectors/notification_permissions.ts @@ -2,9 +2,9 @@ import { BotKind, BrowserKind, ComponentDict, DetectorResponse, State } from '.. export function detectNotificationPermissions({ notificationPermissions, - browser: { browserKind }, + browser }: ComponentDict): DetectorResponse { - if (browserKind !== BrowserKind.Chrome) return false + if (browser.state !== State.Success || browser.value.browserKind !== BrowserKind.Chrome) return false if (notificationPermissions.state === State.Success && notificationPermissions.value) { return BotKind.HeadlessChrome diff --git a/src/detectors/plugins_inconsistency.ts b/src/detectors/plugins_inconsistency.ts index 55439c24..a5279f17 100644 --- a/src/detectors/plugins_inconsistency.ts +++ b/src/detectors/plugins_inconsistency.ts @@ -2,9 +2,10 @@ import { BotKind, BrowserKind, ComponentDict, DetectorResponse, State } from '.. export function detectPluginsLengthInconsistency({ pluginsLength, - browser: { browserKind, isAndroid }, + browser }: ComponentDict): DetectorResponse { - if (pluginsLength.state !== State.Success) return + if (pluginsLength.state !== State.Success || browser.state !== State.Success) return + const { isAndroid, browserKind } = browser.value if (browserKind !== BrowserKind.Chrome || isAndroid) return if (pluginsLength.value === 0) return BotKind.HeadlessChrome } diff --git a/src/detectors/product_sub.ts b/src/detectors/product_sub.ts index 89410b0f..9496a443 100644 --- a/src/detectors/product_sub.ts +++ b/src/detectors/product_sub.ts @@ -1,7 +1,8 @@ import { BotKind, BrowserKind, ComponentDict, DetectorResponse, State } from '../types' -export function detectProductSub({ productSub, browser: { browserKind } }: ComponentDict): DetectorResponse { - if (productSub.state !== State.Success) return false +export function detectProductSub({ productSub, browser }: ComponentDict): DetectorResponse { + if (productSub.state !== State.Success || browser.state !== State.Success) return false + const { browserKind } = browser.value if ( (browserKind === BrowserKind.Chrome || browserKind === BrowserKind.Safari || diff --git a/src/detectors/rtt.ts b/src/detectors/rtt.ts index d0115ea6..a33be461 100644 --- a/src/detectors/rtt.ts +++ b/src/detectors/rtt.ts @@ -1,7 +1,8 @@ import { BotKind, ComponentDict, DetectorResponse, State } from '../types' -export function detectRTT({ rtt, browser: { isAndroid } }: ComponentDict): DetectorResponse { - if (rtt.state !== State.Success) return +export function detectRTT({ rtt, browser }: ComponentDict): DetectorResponse { + if (rtt.state !== State.Success || browser.state !== State.Success) return + const { isAndroid } = browser.value // Rtt is 0 on android webview if (isAndroid) return if (rtt.value === 0) return BotKind.HeadlessChrome diff --git a/src/detectors/window_size.ts b/src/detectors/window_size.ts index b68de7c9..f0e77d0a 100644 --- a/src/detectors/window_size.ts +++ b/src/detectors/window_size.ts @@ -1,8 +1,9 @@ import { BotKind, ComponentDict, DetectorResponse, State } from '../types' -export function detectWindowSize({ windowSize, browser: { documentFocus } }: ComponentDict): DetectorResponse { - if (windowSize.state !== State.Success) return false +export function detectWindowSize({ windowSize, browser }: ComponentDict): DetectorResponse { + if (windowSize.state !== State.Success || browser.state !== State.Success) return false const { outerWidth, outerHeight } = windowSize.value + const { documentFocus } = browser.value // When a page is opened in a new tab without focusing it right away, the window outer size is 0x0 if (!documentFocus) return if (outerWidth === 0 && outerHeight === 0) return BotKind.HeadlessChrome From 2056ef48dbfc4877cb4d2bbed40b2f9d2a1271a3 Mon Sep 17 00:00:00 2001 From: Leo Developer Date: Mon, 11 Sep 2023 13:36:20 +0200 Subject: [PATCH 07/13] fix merge --- src/detectors/plugins_inconsistency.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/detectors/plugins_inconsistency.ts b/src/detectors/plugins_inconsistency.ts index 81951fe4..255940b0 100644 --- a/src/detectors/plugins_inconsistency.ts +++ b/src/detectors/plugins_inconsistency.ts @@ -1,4 +1,4 @@ -import { BotKind, BrowserKind, ComponentDict, DetectorResponse, State } from '../types' +import { BotKind, BrowserEngineKind, BrowserKind, ComponentDict, DetectorResponse, State } from '../types' export function detectPluginsLengthInconsistency({ pluginsLength, @@ -6,6 +6,6 @@ export function detectPluginsLengthInconsistency({ }: ComponentDict): DetectorResponse { if (pluginsLength.state !== State.Success || browser.state !== State.Success) return const { isAndroid, browserKind, browserEngineKind } = browser.value - if (browserKind !== BrowserKind.Chrome || isAndroid() || browserEngineKind !== BrowserEngineKind.Chromium) return + if (browserKind !== BrowserKind.Chrome || isAndroid || browserEngineKind !== BrowserEngineKind.Chromium) return if (pluginsLength.value === 0) return BotKind.HeadlessChrome } From b4eebbc972d82f994fee21cc9606ed97dec3192c Mon Sep 17 00:00:00 2001 From: Leo Developer Date: Mon, 11 Sep 2023 13:59:39 +0200 Subject: [PATCH 08/13] fix circular import thanks auto-import :) --- src/detector.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/detector.ts b/src/detector.ts index 65ba891f..7d0793c9 100644 --- a/src/detector.ts +++ b/src/detector.ts @@ -1,6 +1,7 @@ import { BotDetectionResult, BotDetectorInterface, ComponentDict, DetectionDict } from './types' import { collect, detect } from './api' -import { detectors, sources } from '.' +import { detectors } from './detectors' +import { sources } from './sources' /** * Class representing a bot detector. From 9111960389e7baae9942dc32cd4efbb1f82f69e6 Mon Sep 17 00:00:00 2001 From: Leo Developer Date: Mon, 11 Sep 2023 14:13:36 +0200 Subject: [PATCH 09/13] add type dependency between components and detectors --- src/api.ts | 10 +++++----- src/types.ts | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/api.ts b/src/api.ts index adf0af86..0bced46f 100644 --- a/src/api.ts +++ b/src/api.ts @@ -10,11 +10,11 @@ import { State, } from './types' -export function detect( - components: ComponentDict, - detectors: T, -): [DetectionDict, BotDetectionResult] { - const detections = {} as DetectionDict +export function detect>( + components: T, + detectors: K, +): [DetectionDict, BotDetectionResult] { + const detections = {} as DetectionDict let finalDetection: BotDetectionResult = { bot: false, } diff --git a/src/types.ts b/src/types.ts index 537ba3d9..9d3e5f71 100644 --- a/src/types.ts +++ b/src/types.ts @@ -87,11 +87,11 @@ export type DefaultDetectorDict = typeof detectors */ export type SourceResponse = T extends (...args: any[]) => any ? Awaited> : T -export type AbstractDetector = (...args: any[]) => DetectorResponse +export type AbstractDetector = (components: T) => DetectorResponse export type AbstractSourceDict = Record> -export type AbstractDetectorDict = Record +export type AbstractDetectorDict = Record> export type AbstractComponentDict = Record> @@ -100,7 +100,7 @@ export type AbstractDetectionsDict = Record /** * Represents a dictionary of detectors detection. */ -export type DetectionDict = Record +export type DetectionDict = DefaultDetectorDict> = Record /** * Dictionary of components. From 980248cd730b20ec6d5e26a7ff1ef48343e11492 Mon Sep 17 00:00:00 2001 From: Leo Developer Date: Mon, 11 Sep 2023 14:14:58 +0200 Subject: [PATCH 10/13] style --- src/detectors/eval_length.ts | 6 +++--- src/detectors/notification_permissions.ts | 5 +---- src/detectors/plugins_inconsistency.ts | 9 +++------ src/detectors/product_sub.ts | 2 +- src/detectors/rtt.ts | 2 +- src/detectors/window_size.ts | 2 +- src/types.ts | 5 ++++- 7 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/detectors/eval_length.ts b/src/detectors/eval_length.ts index 2fee19ca..dbcdbd27 100644 --- a/src/detectors/eval_length.ts +++ b/src/detectors/eval_length.ts @@ -3,11 +3,11 @@ import { BrowserEngineKind, BrowserKind, ComponentDict, DetectorResponse, State export function detectEvalLengthInconsistency({ evalLength, - browser: browserComponent + browser: browserComponent, }: ComponentDict): DetectorResponse { if (evalLength.state !== State.Success || browserComponent.state !== State.Success) return - - const { browserKind, browserEngineKind } = browserComponent.value + + const { browserKind, browserEngineKind } = browserComponent.value const length = evalLength.value return ( (length === 37 && !arrayIncludes([BrowserEngineKind.Webkit, BrowserEngineKind.Gecko], browserEngineKind)) || diff --git a/src/detectors/notification_permissions.ts b/src/detectors/notification_permissions.ts index 5f84bf92..b1d6a879 100644 --- a/src/detectors/notification_permissions.ts +++ b/src/detectors/notification_permissions.ts @@ -1,9 +1,6 @@ import { BotKind, BrowserKind, ComponentDict, DetectorResponse, State } from '../types' -export function detectNotificationPermissions({ - notificationPermissions, - browser -}: ComponentDict): DetectorResponse { +export function detectNotificationPermissions({ notificationPermissions, browser }: ComponentDict): DetectorResponse { if (browser.state !== State.Success || browser.value.browserKind !== BrowserKind.Chrome) return false if (notificationPermissions.state === State.Success && notificationPermissions.value) { diff --git a/src/detectors/plugins_inconsistency.ts b/src/detectors/plugins_inconsistency.ts index 255940b0..1d704ef9 100644 --- a/src/detectors/plugins_inconsistency.ts +++ b/src/detectors/plugins_inconsistency.ts @@ -1,11 +1,8 @@ import { BotKind, BrowserEngineKind, BrowserKind, ComponentDict, DetectorResponse, State } from '../types' -export function detectPluginsLengthInconsistency({ - pluginsLength, - browser -}: ComponentDict): DetectorResponse { - if (pluginsLength.state !== State.Success || browser.state !== State.Success) return - const { isAndroid, browserKind, browserEngineKind } = browser.value +export function detectPluginsLengthInconsistency({ pluginsLength, browser }: ComponentDict): DetectorResponse { + if (pluginsLength.state !== State.Success || browser.state !== State.Success) return + const { isAndroid, browserKind, browserEngineKind } = browser.value if (browserKind !== BrowserKind.Chrome || isAndroid || browserEngineKind !== BrowserEngineKind.Chromium) return if (pluginsLength.value === 0) return BotKind.HeadlessChrome } diff --git a/src/detectors/product_sub.ts b/src/detectors/product_sub.ts index 9496a443..74bb10f9 100644 --- a/src/detectors/product_sub.ts +++ b/src/detectors/product_sub.ts @@ -2,7 +2,7 @@ import { BotKind, BrowserKind, ComponentDict, DetectorResponse, State } from '.. export function detectProductSub({ productSub, browser }: ComponentDict): DetectorResponse { if (productSub.state !== State.Success || browser.state !== State.Success) return false - const { browserKind } = browser.value + const { browserKind } = browser.value if ( (browserKind === BrowserKind.Chrome || browserKind === BrowserKind.Safari || diff --git a/src/detectors/rtt.ts b/src/detectors/rtt.ts index a33be461..db3e4a36 100644 --- a/src/detectors/rtt.ts +++ b/src/detectors/rtt.ts @@ -2,7 +2,7 @@ import { BotKind, ComponentDict, DetectorResponse, State } from '../types' export function detectRTT({ rtt, browser }: ComponentDict): DetectorResponse { if (rtt.state !== State.Success || browser.state !== State.Success) return - const { isAndroid } = browser.value + const { isAndroid } = browser.value // Rtt is 0 on android webview if (isAndroid) return if (rtt.value === 0) return BotKind.HeadlessChrome diff --git a/src/detectors/window_size.ts b/src/detectors/window_size.ts index f0e77d0a..dd15b11c 100644 --- a/src/detectors/window_size.ts +++ b/src/detectors/window_size.ts @@ -3,7 +3,7 @@ import { BotKind, ComponentDict, DetectorResponse, State } from '../types' export function detectWindowSize({ windowSize, browser }: ComponentDict): DetectorResponse { if (windowSize.state !== State.Success || browser.state !== State.Success) return false const { outerWidth, outerHeight } = windowSize.value - const { documentFocus } = browser.value + const { documentFocus } = browser.value // When a page is opened in a new tab without focusing it right away, the window outer size is 0x0 if (!documentFocus) return if (outerWidth === 0 && outerHeight === 0) return BotKind.HeadlessChrome diff --git a/src/types.ts b/src/types.ts index 9d3e5f71..28e767de 100644 --- a/src/types.ts +++ b/src/types.ts @@ -100,7 +100,10 @@ export type AbstractDetectionsDict = Record /** * Represents a dictionary of detectors detection. */ -export type DetectionDict = DefaultDetectorDict> = Record +export type DetectionDict = DefaultDetectorDict> = Record< + keyof T, + BotDetectionResult +> /** * Dictionary of components. From 6f4063e2742ad10a8fb25ff9841829b7e038df01 Mon Sep 17 00:00:00 2001 From: Leo Developer Date: Mon, 11 Sep 2023 14:33:44 +0200 Subject: [PATCH 11/13] split browser info source --- src/detectors/eval_length.ts | 17 +++++++++----- src/detectors/notification_permissions.ts | 7 ++++-- src/detectors/plugins_inconsistency.ts | 23 +++++++++++++++---- src/detectors/product_sub.ts | 13 +++++------ src/detectors/rtt.ts | 7 +++--- src/detectors/window_size.ts | 7 +++--- src/sources/android.ts | 5 +++++ src/sources/browser.test.ts | 27 ----------------------- src/sources/browser.ts | 18 --------------- src/sources/browser_engine_kind.ts | 6 +++++ src/sources/browser_kind.ts | 6 +++++ src/sources/document_focus.ts | 5 +++++ src/sources/index.ts | 10 +++++++-- 13 files changed, 77 insertions(+), 74 deletions(-) create mode 100644 src/sources/android.ts delete mode 100644 src/sources/browser.test.ts delete mode 100644 src/sources/browser.ts create mode 100644 src/sources/browser_engine_kind.ts create mode 100644 src/sources/browser_kind.ts create mode 100644 src/sources/document_focus.ts diff --git a/src/detectors/eval_length.ts b/src/detectors/eval_length.ts index dbcdbd27..0b6dcbfa 100644 --- a/src/detectors/eval_length.ts +++ b/src/detectors/eval_length.ts @@ -3,15 +3,20 @@ import { BrowserEngineKind, BrowserKind, ComponentDict, DetectorResponse, State export function detectEvalLengthInconsistency({ evalLength, - browser: browserComponent, + browserKind, + browserEngineKind, }: ComponentDict): DetectorResponse { - if (evalLength.state !== State.Success || browserComponent.state !== State.Success) return + if ( + evalLength.state !== State.Success || + browserKind.state !== State.Success || + browserEngineKind.state !== State.Success + ) + return - const { browserKind, browserEngineKind } = browserComponent.value const length = evalLength.value return ( - (length === 37 && !arrayIncludes([BrowserEngineKind.Webkit, BrowserEngineKind.Gecko], browserEngineKind)) || - (length === 39 && !arrayIncludes([BrowserKind.IE], browserKind)) || - (length === 33 && !arrayIncludes([BrowserEngineKind.Chromium], browserEngineKind)) + (length === 37 && !arrayIncludes([BrowserEngineKind.Webkit, BrowserEngineKind.Gecko], browserEngineKind.value)) || + (length === 39 && !arrayIncludes([BrowserKind.IE], browserKind.value)) || + (length === 33 && !arrayIncludes([BrowserEngineKind.Chromium], browserEngineKind.value)) ) } diff --git a/src/detectors/notification_permissions.ts b/src/detectors/notification_permissions.ts index b1d6a879..dbf63416 100644 --- a/src/detectors/notification_permissions.ts +++ b/src/detectors/notification_permissions.ts @@ -1,7 +1,10 @@ import { BotKind, BrowserKind, ComponentDict, DetectorResponse, State } from '../types' -export function detectNotificationPermissions({ notificationPermissions, browser }: ComponentDict): DetectorResponse { - if (browser.state !== State.Success || browser.value.browserKind !== BrowserKind.Chrome) return false +export function detectNotificationPermissions({ + notificationPermissions, + browserKind, +}: ComponentDict): DetectorResponse { + if (browserKind.state !== State.Success || browserKind.value !== BrowserKind.Chrome) return false if (notificationPermissions.state === State.Success && notificationPermissions.value) { return BotKind.HeadlessChrome diff --git a/src/detectors/plugins_inconsistency.ts b/src/detectors/plugins_inconsistency.ts index 1d704ef9..69d5eebb 100644 --- a/src/detectors/plugins_inconsistency.ts +++ b/src/detectors/plugins_inconsistency.ts @@ -1,8 +1,23 @@ import { BotKind, BrowserEngineKind, BrowserKind, ComponentDict, DetectorResponse, State } from '../types' -export function detectPluginsLengthInconsistency({ pluginsLength, browser }: ComponentDict): DetectorResponse { - if (pluginsLength.state !== State.Success || browser.state !== State.Success) return - const { isAndroid, browserKind, browserEngineKind } = browser.value - if (browserKind !== BrowserKind.Chrome || isAndroid || browserEngineKind !== BrowserEngineKind.Chromium) return +export function detectPluginsLengthInconsistency({ + pluginsLength, + android, + browserKind, + browserEngineKind, +}: ComponentDict): DetectorResponse { + if ( + pluginsLength.state !== State.Success || + android.state !== State.Success || + browserKind.state !== State.Success || + browserEngineKind.state !== State.Success + ) + return + if ( + browserKind.value !== BrowserKind.Chrome || + android.value || + browserEngineKind.value !== BrowserEngineKind.Chromium + ) + return if (pluginsLength.value === 0) return BotKind.HeadlessChrome } diff --git a/src/detectors/product_sub.ts b/src/detectors/product_sub.ts index 74bb10f9..c7d9c079 100644 --- a/src/detectors/product_sub.ts +++ b/src/detectors/product_sub.ts @@ -1,13 +1,12 @@ import { BotKind, BrowserKind, ComponentDict, DetectorResponse, State } from '../types' -export function detectProductSub({ productSub, browser }: ComponentDict): DetectorResponse { - if (productSub.state !== State.Success || browser.state !== State.Success) return false - const { browserKind } = browser.value +export function detectProductSub({ productSub, browserKind }: ComponentDict): DetectorResponse { + if (productSub.state !== State.Success || browserKind.state !== State.Success) return false if ( - (browserKind === BrowserKind.Chrome || - browserKind === BrowserKind.Safari || - browserKind === BrowserKind.Opera || - browserKind === BrowserKind.WeChat) && + (browserKind.value === BrowserKind.Chrome || + browserKind.value === BrowserKind.Safari || + browserKind.value === BrowserKind.Opera || + browserKind.value === BrowserKind.WeChat) && productSub.value !== '20030107' ) return BotKind.Unknown diff --git a/src/detectors/rtt.ts b/src/detectors/rtt.ts index db3e4a36..9237658a 100644 --- a/src/detectors/rtt.ts +++ b/src/detectors/rtt.ts @@ -1,9 +1,8 @@ import { BotKind, ComponentDict, DetectorResponse, State } from '../types' -export function detectRTT({ rtt, browser }: ComponentDict): DetectorResponse { - if (rtt.state !== State.Success || browser.state !== State.Success) return - const { isAndroid } = browser.value +export function detectRTT({ rtt, android }: ComponentDict): DetectorResponse { + if (rtt.state !== State.Success || android.state !== State.Success) return // Rtt is 0 on android webview - if (isAndroid) return + if (android.value) return if (rtt.value === 0) return BotKind.HeadlessChrome } diff --git a/src/detectors/window_size.ts b/src/detectors/window_size.ts index dd15b11c..80b87a17 100644 --- a/src/detectors/window_size.ts +++ b/src/detectors/window_size.ts @@ -1,10 +1,9 @@ import { BotKind, ComponentDict, DetectorResponse, State } from '../types' -export function detectWindowSize({ windowSize, browser }: ComponentDict): DetectorResponse { - if (windowSize.state !== State.Success || browser.state !== State.Success) return false +export function detectWindowSize({ windowSize, documentFocus }: ComponentDict): DetectorResponse { + if (windowSize.state !== State.Success || documentFocus.state !== State.Success) return false const { outerWidth, outerHeight } = windowSize.value - const { documentFocus } = browser.value // When a page is opened in a new tab without focusing it right away, the window outer size is 0x0 - if (!documentFocus) return + if (!documentFocus.value) return if (outerWidth === 0 && outerHeight === 0) return BotKind.HeadlessChrome } diff --git a/src/sources/android.ts b/src/sources/android.ts new file mode 100644 index 00000000..e9a4a9c6 --- /dev/null +++ b/src/sources/android.ts @@ -0,0 +1,5 @@ +import { isAndroid } from '../utils/browser' + +export default function collectIsAndroid(): boolean { + return isAndroid() +} diff --git a/src/sources/browser.test.ts b/src/sources/browser.test.ts deleted file mode 100644 index fa6e39d4..00000000 --- a/src/sources/browser.test.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { isChromium, isGecko, isMobile, isWebKit } from '../../tests/utils' -import { BrowserEngineKind, BrowserKind } from '../types' -import getBrowserInformation from './browser' - -describe('Sources', () => { - describe('browser', () => { - it('returns an expected value', () => { - const value = getBrowserInformation() - - if (isChromium()) { - expect(value.browserEngineKind).toBe(BrowserEngineKind.Chromium) - expect(value.browserKind).toBe(BrowserKind.Chrome) - expect(value.isAndroid).toBe(isMobile()) - } - if (isGecko()) { - expect(value.browserEngineKind).toBe(BrowserEngineKind.Gecko) - expect(value.browserKind).toBe(BrowserKind.Firefox) - expect(value.isAndroid).toBeFalse() - } - if (isWebKit()) { - expect(value.browserEngineKind).toBe(BrowserEngineKind.Webkit) - expect(value.browserKind).toBe(BrowserKind.Safari) - expect(value.isAndroid).toBeFalse() - } - }) - }) -}) diff --git a/src/sources/browser.ts b/src/sources/browser.ts deleted file mode 100644 index 0749e492..00000000 --- a/src/sources/browser.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { BrowserEngineKind, BrowserKind } from '../types' -import { getBrowserEngineKind, getBrowserKind, getDocumentFocus, isAndroid } from '../utils/browser' - -export default function getBrowserInformation(): BrowserInformation { - return { - browserEngineKind: getBrowserEngineKind(), - browserKind: getBrowserKind(), - isAndroid: isAndroid(), - documentFocus: getDocumentFocus(), - } -} - -interface BrowserInformation { - browserEngineKind: BrowserEngineKind - browserKind: BrowserKind - isAndroid: boolean - documentFocus: boolean -} diff --git a/src/sources/browser_engine_kind.ts b/src/sources/browser_engine_kind.ts new file mode 100644 index 00000000..b94222f1 --- /dev/null +++ b/src/sources/browser_engine_kind.ts @@ -0,0 +1,6 @@ +import { BrowserEngineKind } from '../types' +import { getBrowserEngineKind } from '../utils/browser' + +export default function collectBrowserEngineKind(): BrowserEngineKind { + return getBrowserEngineKind() +} diff --git a/src/sources/browser_kind.ts b/src/sources/browser_kind.ts new file mode 100644 index 00000000..621fb7c2 --- /dev/null +++ b/src/sources/browser_kind.ts @@ -0,0 +1,6 @@ +import { BrowserKind } from '../types' +import { getBrowserKind } from '../utils/browser' + +export default function collectBrowserKind(): BrowserKind { + return getBrowserKind() +} diff --git a/src/sources/document_focus.ts b/src/sources/document_focus.ts new file mode 100644 index 00000000..67e542f7 --- /dev/null +++ b/src/sources/document_focus.ts @@ -0,0 +1,5 @@ +import { getDocumentFocus } from '../utils/browser' + +export default function hasDocumentFocus(): boolean { + return getDocumentFocus() +} diff --git a/src/sources/index.ts b/src/sources/index.ts index 0292d6da..276cd982 100644 --- a/src/sources/index.ts +++ b/src/sources/index.ts @@ -1,6 +1,9 @@ +import collectIsAndroid from './android' import getAppVersion from './app_version' -import getBrowserInformation from './browser' +import collectBrowserKind from './browser_kind' +import collectBrowserEngineKind from './browser_engine_kind' import getDocumentElementKeys from './document_element_keys' +import hasDocumentFocus from './document_focus' import getErrorTrace from './error_trace' import getEvalLength from './eval_length' import getFunctionBind from './function_bind' @@ -20,9 +23,12 @@ import getWindowSize, { WindowSizePayload } from './window_size' import checkDistinctiveProperties, { DistinctivePropertiesPayload } from './distinctive_properties' export const sources = { + android: collectIsAndroid, + browserKind: collectBrowserKind, + browserEngineKind: collectBrowserEngineKind, + documentFocus: hasDocumentFocus, userAgent: getUserAgent, appVersion: getAppVersion, - browser: getBrowserInformation, rtt: getRTT, windowSize: getWindowSize, pluginsLength: getPluginsLength, From 866451498889844bd055e1129004ba14e64a639a Mon Sep 17 00:00:00 2001 From: Leo Developer Date: Mon, 11 Sep 2023 14:46:56 +0200 Subject: [PATCH 12/13] move small sources into index.ts --- src/sources/android.ts | 5 ----- src/sources/browser_engine_kind.ts | 6 ------ src/sources/browser_kind.ts | 6 ------ src/sources/document_focus.ts | 5 ----- src/sources/index.ts | 21 +++++++++++++-------- 5 files changed, 13 insertions(+), 30 deletions(-) delete mode 100644 src/sources/android.ts delete mode 100644 src/sources/browser_engine_kind.ts delete mode 100644 src/sources/browser_kind.ts delete mode 100644 src/sources/document_focus.ts diff --git a/src/sources/android.ts b/src/sources/android.ts deleted file mode 100644 index e9a4a9c6..00000000 --- a/src/sources/android.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { isAndroid } from '../utils/browser' - -export default function collectIsAndroid(): boolean { - return isAndroid() -} diff --git a/src/sources/browser_engine_kind.ts b/src/sources/browser_engine_kind.ts deleted file mode 100644 index b94222f1..00000000 --- a/src/sources/browser_engine_kind.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { BrowserEngineKind } from '../types' -import { getBrowserEngineKind } from '../utils/browser' - -export default function collectBrowserEngineKind(): BrowserEngineKind { - return getBrowserEngineKind() -} diff --git a/src/sources/browser_kind.ts b/src/sources/browser_kind.ts deleted file mode 100644 index 621fb7c2..00000000 --- a/src/sources/browser_kind.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { BrowserKind } from '../types' -import { getBrowserKind } from '../utils/browser' - -export default function collectBrowserKind(): BrowserKind { - return getBrowserKind() -} diff --git a/src/sources/document_focus.ts b/src/sources/document_focus.ts deleted file mode 100644 index 67e542f7..00000000 --- a/src/sources/document_focus.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { getDocumentFocus } from '../utils/browser' - -export default function hasDocumentFocus(): boolean { - return getDocumentFocus() -} diff --git a/src/sources/index.ts b/src/sources/index.ts index 276cd982..cb9498a2 100644 --- a/src/sources/index.ts +++ b/src/sources/index.ts @@ -1,9 +1,5 @@ -import collectIsAndroid from './android' import getAppVersion from './app_version' -import collectBrowserKind from './browser_kind' -import collectBrowserEngineKind from './browser_engine_kind' import getDocumentElementKeys from './document_element_keys' -import hasDocumentFocus from './document_focus' import getErrorTrace from './error_trace' import getEvalLength from './eval_length' import getFunctionBind from './function_bind' @@ -21,12 +17,21 @@ import getWebGL from './webgl' import getWindowExternal from './window_external' import getWindowSize, { WindowSizePayload } from './window_size' import checkDistinctiveProperties, { DistinctivePropertiesPayload } from './distinctive_properties' +import { getBrowserEngineKind, getBrowserKind, getDocumentFocus, isAndroid } from '../utils/browser' export const sources = { - android: collectIsAndroid, - browserKind: collectBrowserKind, - browserEngineKind: collectBrowserEngineKind, - documentFocus: hasDocumentFocus, + android: function collectIsAndroid() { + return isAndroid() + }, + browserKind: function collectBrowserKind() { + return getBrowserKind() + }, + browserEngineKind: function collectBrowserEngineKind() { + return getBrowserEngineKind() + }, + documentFocus: function hasDocumentFocus() { + return getDocumentFocus() + }, userAgent: getUserAgent, appVersion: getAppVersion, rtt: getRTT, From 7efa6d8cc85f65df85a6609eb6dafb484c2c6588 Mon Sep 17 00:00:00 2001 From: Leo Developer Date: Mon, 11 Sep 2023 14:51:25 +0200 Subject: [PATCH 13/13] remove unused function wrapper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤦🤦 --- src/sources/index.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/sources/index.ts b/src/sources/index.ts index cb9498a2..1dddac88 100644 --- a/src/sources/index.ts +++ b/src/sources/index.ts @@ -20,18 +20,10 @@ import checkDistinctiveProperties, { DistinctivePropertiesPayload } from './dist import { getBrowserEngineKind, getBrowserKind, getDocumentFocus, isAndroid } from '../utils/browser' export const sources = { - android: function collectIsAndroid() { - return isAndroid() - }, - browserKind: function collectBrowserKind() { - return getBrowserKind() - }, - browserEngineKind: function collectBrowserEngineKind() { - return getBrowserEngineKind() - }, - documentFocus: function hasDocumentFocus() { - return getDocumentFocus() - }, + android: isAndroid, + browserKind: getBrowserKind, + browserEngineKind: getBrowserEngineKind, + documentFocus: getDocumentFocus, userAgent: getUserAgent, appVersion: getAppVersion, rtt: getRTT,