> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fingerprint.com/llms.txt
> Use this file to discover all available pages before exploring further.

# load function

> API reference for the JavaScript agent's  function

export const DeprecatedVersion = ({currentPath}) => <Warning>
    This version is deprecated. See the{" "}
    <a href="/reference/api-deprecation-policy">deprecation policy</a> and use
    the <a href={currentPath}>current version</a> instead.
  </Warning>;

<DeprecatedVersion currentPath="/reference/js-agent-v4-start-function" />

This page contains the API Reference for the JavaScript agent's `load()` function or its equivalent in your frontend library. The function is exported from the [@fingerprintjs/fingerprintjs-pro](https://www.npmjs.com/package/@fingerprintjs/fingerprintjs-pro) NPM package.

Call the `load()` function to initialize the JavaScript agent for your Fingerprint workspace.

If you are just getting started with Fingerprint, we recommend reading the following guides first:

* [Install the JavaScript agent](/docs/install-the-javascript-agent)
* [Identify visitors](/docs/identify-visitors)

If you encountered errors using the JavaScript agent, see the [Error handling reference](/reference/v3/js-agent-error-handling).

## `load()` options

To configure the agent, pass parameters into the `load()` function or its equivalent in your [frontend library](/docs/frontend-libraries).

### `apiKey`

> **Required**: yes for NPM installation <br />
> **Type**: `string`

Your public API key to authenticate the agent. You can get one at [dashboard.fingerprint.com](https://dashboard.fingerprint.com). If you log into this documentation portal through the dashboard, you will be able to see your personal API key in the example below.

Example usage:

```javascript JavaScript theme={"theme":"github-dark-dimmed"}
const fpPromise = FingerprintJS.load({ apiKey: "PUBLIC_API_KEY" })
```

The parameter is required for the NPM installation method and optional for the CDN (where the key is a part of the URL).

### `region`

> **Required**: no<br />
> **Default**: `"us"` **Type**: `string` **Available values**: `"us"`, `"eu"` and `"ap"`

Use this parameter to specify the [region](/docs/regions) you picked for your workspace during registration (defaults to `us`).

The Fingerprint Platform CDN can usually determine the region automatically using your API Key. Nevertheless, we recommend you specify it explicitly. Our [proxy integrations](/docs/protecting-the-javascript-agent-from-adblockers) rely on the `region` parameter, as they do not have access to the same internal API that our CDN does. Even if you use our CDN, specifying the region explicitly will keep your JavaScript agent working correctly if our internal API is temporarily disrupted.

The parameter is ignored when both the `endpoint` and `tlsEndpoint` parameters are used.

Example:

```javascript JavaScript theme={"theme":"github-dark-dimmed"}
const fpPromise = FingerprintJS.load({ region: 'eu' })
```

### `endpoint`

> **Required**: no<br />
> **Default**: (depends on the region) **Type**: `string | string[]`

This parameter should only be used with the [Custom subdomain](/docs/custom-subdomain-setup#4-configuring-the-javascript-agent) or a cloud [proxy integration](/docs/protecting-the-javascript-agent-from-adblockers). Specify your custom endpoint URL here.

Multiple endpoints can be set using an array. The JavaScript agent will try to send the request with the first endpoint, and if the request fails, retry the request with the second endpoint, and so on. Use `FingerprintJS.defaultEndpoint` to fall back to the default endpoint.

```javascript JavaScript theme={"theme":"github-dark-dimmed"}
import * as FingerprintJS from '@fingerprintjs/fingerprintjs-pro'

const fpPromise = FingerprintJS.load({
  apiKey: 'PUBLIC_API_KEY',
  endpoint: [
    'https://fp.example.com', // This endpoint will be used primarily
    FingerprintJS.defaultEndpoint, // The default endpoint will be used if the primary fails
  ],
})
```

JavaScript agent will throw an error if an empty array is given.

### `tlsEndpoint` (deprecated)

> **Required**: no<br />
> **Default**: (a subpath of the `endpoint`) **Type**: `string | string[]` **Since**: v3.1.0

**As of JavaScript agent version 3.8.22, this option has been deprecated and will likely be removed in the next major version.**

Your custom TLS endpoint URL address.

Multiple endpoints can be set with an array. The JavaScript agent will try to send the request with the first endpoint, and if the request fails, retry the request with the second endpoint, and so on. Use `FingerprintJS.defaultTlsEndpoint` to fall back to the default endpoint.

### `disableTls` (deprecated)

> **Required**: no<br />
> **Default**: `false` **Type**: `string` **Since**: v3.4.0

**As of JavaScript agent version 3.8.22, this option has been deprecated and will likely be removed in the next major version.**

Set to `true` to disable the extra TLS request. This is not recommended as it will negatively affect your identification accuracy.

### `storageKey`

> **Required**: no<br />
> **Default**: `'_vid'` **Type**: `string`

Name of key to store data in visitor browsers. The data is stored in cookies and local storage. You shouldn't change this parameter once your code runs in production. The change will cause the data in visitor browsers to be purged which will decrease the identification accuracy.

### `scriptUrlPattern`

> Only for NPM installation<br />
> **Required**: no<br />
> **Default**: `'https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js'` **Type**: `string | string[]` **Since**: v3.6.0

By default, the JavaScript agent downloads the code from our CDN. The `scriptUrlPattern` option overrides this default by providing a pattern of the URL from where the JavaScript agent downloads the latest code at runtime. This is commonly used in two scenarios:

* To set up the agent download URL through your [Custom Subdomain](/docs/custom-subdomain-setup#4-configuring-the-javascript-agent).
* To correctly set up the agent download through [proxy integrations](/docs/protecting-the-javascript-agent-from-adblockers).

JavaScript agent automatically substitutes the following substrings in the provided `scriptUrlPattern` string:

* `<version>` — the major version of the JavaScript agent;
* `<apiKey>` — the public key set via the `apiKey` parameter;
* `<loaderVersion>` — the exact version of the `@fingerprintjs/fingerprintjs-pro` package.

You can set multiple endpoints using an array. The JavaScript agent will try to download the code from the first URL, and if it fails, retry to download with the second URL, and so on. Use `FingerprintJS.defaultScriptUrlPattern` to fall back to the default URL.

```javascript JavaScript theme={"theme":"github-dark-dimmed"}
import * as FingerprintJS from '@fingerprintjs/fingerprintjs-pro'

const fpPromise = FingerprintJS.load({
  apiKey: 'PUBLIC_API_KEY',
  scriptUrlPattern: [
    // This endpoint will be used primarily
    '/myproxy/v<version>/<apiKey>/loader_v<loaderVersion>.js',

    // The default endpoint will be used if the primary fails
    FingerprintJS.defaultScriptUrlPattern,
  ],
})
```

### `urlHashing`

> Only for NPM installation<br />
> **Required**: no **Default**: `undefined` (no hashing) **Type**: `UrlHashing` **Since**: v3.11.0

`urlHashing` flags ensure no PII or secret data get unintentionally leaked through `path`, `query` or `fragment` values in an URL by replacing raw values with a securely encoded hash.

<Note>
  `urlHashing` configuration has no effect on performance or accuracy of Identification and Smart Signals products.
</Note>

The `UrlHashing` type has the following configuration structure

```typescript TypeScript theme={"theme":"github-dark-dimmed"}
type UrlHashing = {
  path?: boolean
  query?: boolean
  fragment?: boolean
}
```

* `path` replaces the **path** portion of the URL with a securely encoded hash if set to `true`
* `query` replaces the **query** portion of the URL with a securely encoded hash if set to `true`
* `fragment` replaces the **fragment** portion of the URL with a securely encoded hash if set to `true`

The portion of the URL that contains either `path`, `query` or `fragment` is replaced with a single value that represents a securely encoded hash of the original URL parts.

Example:

The following example illustrates the behavior of our JavaScript agent without and with the `urlHashing` flags configured. **Original URL** represents the URL we would normally send to our backend (in an obfuscated form) **Result** shows how our JavaScript agent hashes the URL if the `path`, `query` and `fragment` parameters of `urlHashing` were set to `true` respectively. The order of the query parameters has no effect on the output hash.

**Original URL**

`https://example.com/test?param1=somePII&param2=clientSecret&param3=tokenValue#id342324`

| `path` enabled | `query` enabled | `fragment` enabled | Result                                                                                                                                                    |
| -------------- | --------------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| NO             | YES             | NO                 | `https://example.com/test?UNrfPps8c1O_mrVgqvhVju4SCMDncBNJat8_iDK-00M#id342324`                                                                           |
| YES            | NO              | NO                 | `https://example.com/n4bQgYhMfWWaL-qgxVrQFaO_TxsrC4Is0V1sFbDwCgg?param1=somePII&param2=clientSecret&param3=tokenValue#id342324`                           |
| NO             | NO              | YES                | `https://example.com/test?param1=somePII&param2=clientSecret&param3=tokenValue#rws4nbTyh7ALUYP6QsxMBWqGTa2T0QzIWHBSRr0rHDo`                               |
| YES            | YES             | YES                | `https://example.com/n4bQgYhMfWWaL-qgxVrQFaO_TxsrC4Is0V1sFbDwCgg?UNrfPps8c1O_mrVgqvhVju4SCMDncBNJat8_iDK-00M#rws4nbTyh7ALUYP6QsxMBWqGTa2T0QzIWHBSRr0rHDo` |

<Note>
  If either `query`, `param` or `fragment` part are empty, they are returned as-is without hashing. As an example URL `https://example.com/?#` stays as is.
</Note>

## `load()` response

The `load()` function returns a Promise that resolves to the JavaScript agent instance. The instance has a [`get()`](/reference/v3/js-agent-get-function) method you can use to identify visitors.

```javascript JavaScript theme={"theme":"github-dark-dimmed"}
import * as FingerprintJS from '@fingerprintjs/fingerprintjs-pro';

async function identifyVisitor() {
  const agent = await FingerprintJS.load({ apiKey: 'PUBLIC_API_KEY' })
  const result = await agent.get()
  console.log(result.visitorId)
}
```

See [Configuring the JavaScript agent](/docs/install-the-javascript-agent#configuring-the-agent) for more details.
