Javascript 如何异步加载指纹js并获取访问者id
我将javascript脚本与旧版本的iMacros(v8.9.7)一起使用 我有点困惑如何让指纹JS正常工作 我的用例: 1-从CDN异步加载指纹JS 2-将visitorID存储到变量中 我的代码:Javascript 如何异步加载指纹js并获取访问者id,javascript,firefox,imacros,xpcom,Javascript,Firefox,Imacros,Xpcom,我将javascript脚本与旧版本的iMacros(v8.9.7)一起使用 我有点困惑如何让指纹JS正常工作 我的用例: 1-从CDN异步加载指纹JS 2-将visitorID存储到变量中 我的代码: Components.utils.import("resource://gre/modules/Promise.jsm"); Components.utils.import("resource://gre/modules/devtools/Console.jsm"); functi
Components.utils.import("resource://gre/modules/Promise.jsm");
Components.utils.import("resource://gre/modules/devtools/Console.jsm");
function initFingerprintJS() {
FingerprintJS.load()
.then(fp => fp.get())
.then(result => {
const visitorId = result.visitorId;
window.console.log(visitorId);
});
}
const loadScript = (src, async = true, type = "text/javascript") => {
return new Promise((resolve, reject) => {
try {
const el = window.document.createElement("script");
const container = window.document.head || window.document.body;
el.type = type;
el.async = async;
el.src = src;
el.addEventListener("load", () => {
resolve({ status: true });
});
el.addEventListener("error", () => {
reject({
status: false,
message: `Failed to load the script ${src}`
});
});
container.appendChild(el);
} catch (err) {
reject(err);
}
});
};
function get_fingerprint() {
loadScript("https://cdn.jsdelivr.net/npm/@fingerprintjs/fingerprintjs@3/dist/fp.min.js")
.then((data) => {
window.console.log("Script loaded successfully", data);
initFingerprintJS();
})
.catch((err) => {
window.console.error(err);
});
}
FINGERPRINT
您试图在传统web环境中加载一个现代库:它甚至支持库需要启动的JS语言功能吗?我尝试了另一个内部带有函数的外部脚本。函数仍然是“未定义的”,那么,听起来您的问题与您自己的代码完全无关。是时候删除这个问题并做一些测试,看看你的imacros版本到底接受了什么?“它”(imacros v8.9.7 for FF)接受FF JS运行时引擎接受并可以做的“一切”。。。(至少在FF v55.0.3之前,某些Func被FF56破坏…)。