查看: 27|回复: 1

[文章教程] FingerprintJS 一个开源的客户端浏览器指纹库

[复制链接]
xuanxiao 发表于 2026-3-31 10:35:49 | 显示全部楼层 |阅读模式
FingerprintJS 是一个用于浏览器指纹识别的 JavaScript 库。它通过收集浏览器和设备的各种特征来生成一个唯一的标识符,即“指纹”。这个指纹可以用于识别和跟踪用户,即使他们清除了 cookies 或使用隐私模式浏览。

功能特性
跨浏览器兼容性:支持主流浏览器,包括 Chrome、Firefox、Safari、Edge 等。
高准确性:通过收集多种设备和浏览器特征,生成高度唯一的指纹。
轻量级:库体积小,加载速度快,不影响页面性能。
隐私友好:不依赖于 cookies、localStorage 或其他持久性存储,减少隐私风险。
易于集成:提供简单的 API,易于在现有项目中集成。
跨浏览器兼容性:支持所有主流浏览器,包括 Chrome、Firefox、Safari、Edge 等。
安全:生成的指纹通常是加密的,以减少数据泄露的风险。
自定义:开发者可以根据自己的需求选择性地启用或禁用某些数据收集功能,以符合特定的隐私政策或法律要求。

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>FingerprintJS 示例</title>
  6.    

  7. </head>
  8. <body>
  9.     <h1>您的浏览器指纹是:</h1>
  10.     <p id="fingerprint"></p>
  11.    

  12.         <script>
  13.   // Initialize the agent at application startup.
  14.   // If you're using an ad blocker or Brave/Firefox, this import will not work.
  15.   // Please use the NPM package instead: https://t.ly/ORyXk
  16.   const fpPromise = import('https://openfpcdn.io/fingerprintjs/v5')
  17.     .then(FingerprintJS => FingerprintJS.load())

  18.   // Get the visitor identifier when you need it.
  19.   fpPromise
  20.     .then(fp => fp.get())
  21.     .then(result => {
  22.       // This is the visitor identifier:
  23.       const visitorId = result.visitorId
  24.           
  25.       console.log(visitorId)
  26.           
  27.             // 显示指纹
  28.        document.getElementById('fingerprint').textContent = result.visitorId;
  29.     })
  30. </script>
  31. </body>
  32. </html>
复制代码
 楼主| xuanxiao 发表于 2026-3-31 10:45:41 | 显示全部楼层
ScreenShot_2026-03-31_104609_471.png
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>FingerprintJS Demo</title>
    <script>
        // 使用CDN方式引入(国内推荐使用jsDelivr)
        const fpPromise = import('https://cdn.jsdelivr.net/npm/@fingerprintjs/fingerprintjs@5/dist/fp.esm.min.js')
            .then(FingerprintJS => FingerprintJS.load({
                debug: true  // 开启调试模式
            }))

        // 异步获取访客标识符
        async function getVisitorId() {
            try {
                const fp = await fpPromise
                const result = await fp.get()
               
                console.log('访客ID:', result.visitorId)
                console.log('置信度:', result.confidence.score)
                console.log('组件详情:', result.components)
               
                return result
            } catch (error) {
                console.error('指纹识别失败:', error)
            }
        }

        // 页面加载完成后执行
        document.addEventListener('DOMContentLoaded', getVisitorId)
    </script>
</head>
<body>
    <h1>FingerprintJS演示页面</h1>
    <p>查看控制台输出获取访客标识符信息</p>
</body>
</html>
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表

在线客服

售前咨询
售后咨询
服务热线
023-58418553
微信公众号