Skip to content

Latest commit

 

History

History
108 lines (89 loc) · 2.94 KB

File metadata and controls

108 lines (89 loc) · 2.94 KB

Migrating BotD v1 to v2

This guide shows how to migrate your code from BotD version 1 to version 2.

CDN

<script>
    // Initialize an agent at application startup.
-   const botdPromise = import('https://openfpcdn.io/botd/v1').then((BotD) =>
+   const botdPromise = import('https://openfpcdn.io/botd/v2').then((BotD) =>
        BotD.load(),
    )
    // Get the bot detection result when you need it.
    botdPromise
        .then((botd) => botd.detect())
        .then((result) => console.log(result))
        .catch((error) => console.error(error))
</script>

NPM or Yarn

Update the package version:

npm install @fingerprintjs/fingerprintjs
# or
yarn add @fingerprintjs/fingerprintjs

JavaScript output and browser support

Updated compilation target

The distributed bundles are now compiled to ES2018 instead of ES5. Modern build tools already handle this target, but any pipeline that assumed ES5 output (for example, older minifiers or ES5-only runtime environments) may require updates to accept or transpile ES2018 syntax.

Supported browsers

The minimum browser versions officially supported by BotD are listed in the browser support list. Confirm that the browsers you rely on meet or exceed these versions before deploying v2

Transpiling to ES5 when required

If you must keep ES5-compatible artifacts—for example, when embedding BotD into legacy applications—you now need to run that transpilation yourself. A typical setup using Babel might look like:

// babel.config.json
{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "ie": "11"
        },
        "useBuiltIns": "usage",
        "corejs": "3.38"
      }
    ]
  ]
}

Or, if you compile with TypeScript, adjust your tsconfig.json:

{
  "compilerOptions": {
    "target": "ES5",
    "downlevelIteration": true
  }
}

Make sure that your bundler (Webpack, Rollup, Vite, etc.) picks up these settings so that the BotD package is transpiled along with your application code. For Webpack with babel-loader, explicitly include the library so it is processed despite the default node_modules exclusion:

// webpack.config.js
module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.m?js$/,
        exclude: /node_modules\/(?!@fingerprintjs\/botd)/, // this will transpile BotD
        use: {
          loader: 'babel-loader',
          options: {
            presets: [
              [
                '@babel/preset-env',
                {
                  targets: { ie: '11' },
                  useBuiltIns: 'usage',
                  corejs: '3.38'
                }
              ]
            ]
          }
        }
      }
    ]
  }
}

If you use TypeScript, ensure that the bundler reads your tsconfig.json (for example via ts-loader or babel-loader with @babel/preset-typescript) so that the downlevel settings apply to both your code and BotD.