如何解决与服务人员的指纹
所以,我目前正在学习 Service Worker,我想测试的一个方面是如何使用 Service Worker 进行指纹识别。
目前,我正在使用 https://github.com/LukasDrgon/fingerprintjs2 来实现指纹功能,并从 StackOverflow 上的 link 获取帮助。
但是当我尝试重新加载页面时,它给出了一个错误提示
Uncaught (in promise) TypeError: ServiceWorker script at http://localhost:9000/sw.js for scope http://localhost:9000/ threw an exception during script evaluation.
这就是我的代码的样子。
// import fp from "fingerprintjs2";
function receivePushNotification(event) {
console.log("[Service Worker] Push Received.");
const { image,tag,url,title,text } = event.data.json();
const options = {
data: url,body: text,icon: image,vibrate: [200,100,200],tag: tag,image: image,badge: "https://spyna.it/icons/favicon.ico",actions: [{ action: "Detail",title: "View",icon: "https://via.placeholder.com/128/ff0000" }]
};
// new Fingerprint2().get(function(result,components){
// console.log(result); //a hash,representing your device fingerprint
// console.log(components); // an array of FP components
// });
event.waitUntil(self.registration.showNotification(title,options));
}
function openPushNotification(event) {
console.log("[Service Worker] Notification click Received.",event.notification.data);
event.notification.close();
event.waitUntil(clients.openWindow(event.notification.data));
}
self.addEventListener("push",receivePushNotification);
self.addEventListener("notificationclick",openPushNotification);
console.log("here in service Worker")
//fingerprint code below this line
var info = {};
new Fingerprint2().get(function(result,components) {
info.fingerprint = result;
afterFingerprintIsCalculated();
});
function afterFingerprintIsCalculated() {
alert(info.fingerprint);
}
// BETTER (no global state)
new Fingerprint2().get(function(result,components) {
var info = {
fingerprint: result
};
processFingerprint(info);
});
function processFingerprint(data) {
alert(data.fingerprint);
}
让我知道如何使其工作并使用服务工作者获取浏览器的指纹。我目前是 JS 和这个范式的新手,如果你有其他有用的(和易于理解的链接),也请分享。谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。