From 91880fdb013bb5b57b1857dc2e0337d0426dd30a Mon Sep 17 00:00:00 2001 From: Sergey M Date: Mon, 27 Nov 2023 18:13:33 +1000 Subject: [PATCH] Return the `monitoring` option documentation --- docs/api.md | 12 +++++++++++- src/index.ts | 15 +++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/docs/api.md b/docs/api.md index 8735b8cf..83790d42 100644 --- a/docs/api.md +++ b/docs/api.md @@ -53,6 +53,16 @@ A request includes the following information: - The HTTP headers that the client sends, including the origin and the referrer of the page where the library runs - The IP of the client +You can turn off these requests by using the `monitoring` option: + +```diff +const botdPromise = BotD.load({ ++ monitoring: false +}) +``` + +💡 Scripts downloaded from our CDN (https://openfpcdn.io) have monitoring disabled by default. + ### CommonJS syntax: ```js @@ -67,7 +77,7 @@ load() ## API -#### `BotD.load(): Promise` +#### `BotD.load({ monitoring?: boolean }): Promise` Builds an instance of `BotDetector`. We recommend calling it as early as possible, ideally during application startup. It returns a promise which you can chain on to call `BotDetector` methods later. diff --git a/src/index.ts b/src/index.ts index 515096e9..6b08715b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,17 @@ import { detectors } from './detectors' import { BotdError, BotDetectorInterface, BotKind, BotDetectionResult } from './types' import { collect, detect } from './api' +/** + * Options for BotD loading + */ +export interface LoadOptions { + /** + * Set `false` to disable the unpersonalized AJAX request that the agent sends to collect installation statistics. + * It's always disabled in the version published to the FingerprintJS CDN. + */ + monitoring?: boolean +} + /** * Sends an unpersonalized AJAX request to collect installation statistics */ @@ -24,8 +35,8 @@ function monitor() { } } -export async function load(options?: Record): Promise { - if (options?.monitoring ?? true) { +export async function load({ monitoring = true }: Readonly = {}): Promise { + if (monitoring) { monitor() } const detector = new BotDetector()