js 获取设备或浏览器唯一标识的方式

网上的一些回复有很多,反正就是获取不到h5的机器码,或者mac地址,所以只能获取浏览器唯一标识。

fingerprint获取的方式,代码:

 
  1. const fpPromise = new Promise((resolve, reject) => {
  2. const script = document.createElement('script')
  3. script.onload = resolve
  4. script.onerror = reject
  5. script.async = true
  6. script.src = 'https://cdn.jsdelivr.net/npm/'
  7. + '@fingerprintjs/fingerprintjs@3/dist/fp.min.js'
  8. document.head.appendChild(script)
  9. })
  10. .then(() => FingerprintJS.load())
  11.  
  12. // Get the visitor identifier when you need it.
  13. fpPromise
  14. .then(fp => fp.get())
  15. .then(result => {
  16. // This is the visitor identifier:
  17. const visitorId = result.visitorId
  18. console.log(visitorId)
  19. })
 

github:https://github.com/fingerprintjs/fingerprintjs

posted @ 2024-01-01 22:26  CharyGao  阅读(2856)  评论(0编辑  收藏  举报