javascript - 与服务人员进行指纹识别
问题描述
所以,我目前正在学习服务工作者,我想测试的方面之一是如何使用服务工作者进行指纹识别。
目前,我正在使用https://github.com/LukasDrgon/fingerprintjs2来实现指纹功能并从StackOverflow 上的此链接获取帮助。
但是当我尝试重新加载页面时,它给出了一个错误说
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 和这种范式很陌生,如果您有其他有用的(且易于理解的链接),也请分享。谢谢你。
解决方案
推荐阅读
- amazon-web-services - 使用云形成在 AWS EC2 实例中创建文件的最佳实践
- java - 访问匿名类之外的变量
- java - Spring OAuth2 - 客户端凭据授予类型中的用户信息
- gae-python27 - Python使用endswith获取元组索引
- java - 在多个线程中运行测试时,在使用 EndTest 安全结束测试之前调用了 Close
- python - 从 Maya 镜头列表中获取 Attr
- php - Volley 字符串请求发布参数在 php.ini 中始终为空。
- javascript - 对于使用 Inputmask 插件屏蔽的 texbox,第一次无法在月份字段中键入 01
- microsoft-dynamics - 为 PowerApp 平台中的 CDS 创建的连接未出现在下拉列表中,用于在 PowerApp 管理门户中创建 ConnectionSet
- java - 如何使用具有多种格式的弹簧批处理读取复杂的文本文件