Fingerprint is a device intelligence platform offering 99.5% accurate visitor identification.
This repository contains an example Chrome extension that uses the Fingerprint Pro JavaScript agent.
- Chromium-based browser (Chrome, Edge, Opera, etc.)
You can download the latest version of the extension from the Releases page. To install the extension, follow these steps:
- Head to
chrome://extensions/page in your browser. - Click Load unpacked.
- Select downloaded
chrome-extension.zipfile. - You should see the FingerprintJS Example Browser Extension extension, make sure that it is activated.
The Chrome extension environment has limited capabilities for external scripts running within content scripts. The solution is split into two parts - chrome-extension and website.
The website uses the Fingerprint Pro JavaScript agent as it normally would, and communicates with the Chrome extension. It is hosted on Github Pages.
Provides a sample extension that consists of a popup page, background, and content script.
This repository contains two strategies that make our FingerprintJS Pro JavaScript agent work in the Chrome extension environment.
When the extension needs to obtain data from the FingerprintJS Pro JavaScript agent, it creates a new window (via chrome.windows.create) with the URL of the website and waits for a message from it.
- We send message to background script
{"type": "get-visitor-id"}. - The background script creates a new window that points to the website URL. The window is visible but without focus.
- The website uses the FingerprintJS Pro JavaScript agent to obtain data and passes it back to the Chrome extension via native communication channel.
- The background scripts wait for the message and then pass it back to the sender.
- Created window is closed.
To debug the created window, you can comment out the
await chrome.windows.remove(currentWindow.id);incloseCurrentWindowfunction inpackages/chrome-extension/src/background.ts.
This strategy can be found in packages/chrome-extension/src/fingerprint/strategies/newWindow.strategy.ts.
- We append an iframe to the DOM of a currently open page in the browser with the URL of the website. It can be used in the extension popup as well.
- The website uses the FingerprintJS Pro JavaScript agent to obtain data, and passes it back to the parent window via
window.parent.postMessage. - The chrome-extension awaits the message.
This strategy can be found in packages/chrome-extension/src/fingerprint/strategies/iframe.strategy.ts.
Note: Implementation of both of these strategies is not perfect, ideally they should also handle time-out scenarios and connection issues with the website. It was decided to leave it out to keep it simple.
After cloning the repository perform these operations:
- Run
pnpm installto install dependencies. - Copy
.env.distto.envand provide your FingerprintJS PublicAPI_KEY.- If you want to develop the extension locally, you also need to set
WEBSITE_URL=https://localhost:8080/. - You will also need to set the
EXTENSION_IDS, we will get back to it late.
- If you want to develop the extension locally, you also need to set
- Run
pnpm extension:watchto build the extension on changes. - Install the unpacked extension in your browser. To do that:
- Head to
chrome://extensions/page in your browser. - Click Load unpacked.
- Select
packages/chrome-extension/builddirectory. - You should see the FingerprintJS Example Browser Extension extension, make sure that it is activated.
- Copy the
extension ID:
- Paste it into
.envasEXTENSION_IDS. It is needed, so that the website can communicate with the extension.
- Head to
- Run
pnpm website:startto run the website.- Note: Required
chromeAPI for New window strategy is not available on pages that are not served viaHTTPS, so the website is served onhttps://localhost:8080/. You can safely ignore the warning regarding the certificate. - In order to use the Custom subdomain set
API_ENDPOINT=YOUR_API_ENDPOINTin.env.
- Note: Required
To ask questions or provide feedback, use Issues. If you need private support, please email us at [email protected].
This project is licensed under the MIT license. See the LICENSE file for more info.