Using Fingerprint in Google Chrome Extensions
A typical use-case represents getting a validvisitorId among other result data via your extension. After validating it with the Server API or webhooks, data provided by Fingerprint might be crucial for your internal decision making, user scoring, and protecting sensitive actions for your business.
There are two general strategies to integrate Fingerprint into an extension. You can get Fingerprint result by opening your website temporarily in a new window. Another way demonstrates injecting the FingerprintJS JavaScript agent into the website’s iframe and performing fingerprinting there.
Both solutions are showcased in the Chrome extension repository. The example extension is also available on the Chrome Web Store.
New window strategy
With this approach, the Chrome extension creates a new window that points to an external website hosted by you. This website uses our Fingerprint agent to obtain theresult. This data is then passed back to the extension using a native communication channel.
Sample use
- Configure and serve a publicly available web page containing the Fingerprint JavaScript agent. It’s recommended to use the Custom subdomain setup or one of our cloud proxy integration to protect the JavaScript agent from ad blockers and increase accuracy. This website must be served over HTTPS.
JavaScript
- In the extension’s
manifest.json, add theexternally_connectablemanifest property. Make sure you’ve specified theservice_workerproperty in thebackgroundsection as well.
JavaScript
- Add the following code snippet into your background script. It will allow you to obtain results from Fingerprint inside your extension’s codebase.
JavaScript
- Receive and use the
resultdata in your extension’s logic.
JavaScript
Iframe strategy
With this strategy, the extension appends an iframe into the DOM with the URL of the external website and communicates with it using Window.postMessage() API. Alternatively, you can append the iframe into the DOM served on the extension page (e.g. in the popup). There are several benefits of not using a content script:- Other extensions don’t have access to the iframe content (e.g. adblockers).
- There are no required special permissions in the
manifest.json. - Several anti-fingerprinting techniques and tracking protections can’t identify and block this approach.
Sample use
- Configure and serve a publicly available web page containing the Fingerprint JavaScript agent. It’s recommended to use the Custom subdomain. The website must be served over HTTPS.
- Add the following code to your extension where you need to get
resultdata.
DOM API and background scriptsWith this approach, your extension needs access to the DOM API, therefore, according to the Manifest v3 limitations, it’s not possible to use the following snippet in the background script.
JavaScript