ReferenceError:未定义导航器

时间:2018-04-20 18:46:53

标签: javascript node.js npm fingerprintjs2

我试图在javascript中使用fingerprintjs npm模块获取浏览器指纹。但它给了我以下错误。 Please see this image for errors

我的代码是:

const Fingerprint = require('fingerprintjs2');
const express = require('express');
const cors = require('cors');
const mysql = require('mysql');
const app = express();

const fpInstance = new Fingerprint();
fpInstance.get((result,err)=>{
    if(err){
        console.log('Error obtained',err)
    }
    else{
        console.log(result)
    } 
})

请尽早帮助我..

1 个答案:

答案 0 :(得分:1)

我发现fingerprintjs2是一个Javascript库,在Node.js中不能正常工作。幸运的是,该服务器的服务器端版本已经发布,即Fingerprint express middleware,用于所谓的被动指纹识别

安装: npm install express-fingerprint

用法:

var Fingerprint = require('express-fingerprint')

app.use(Fingerprint({
    parameters:[
        // Defaults
        Fingerprint.useragent,
        Fingerprint.acceptHeaders,
        Fingerprint.geoip,

        // Additional parameters
        function(next) {
            // ...do something...
            next(null,{
            'param1':'value1'
            })
        },
        function(next) {
            // ...do something...
            next(null,{
            'param2':'value2'
            })
        },
    ]
}))

app.get('*',function(req,res,next) {
    // Fingerprint object
    console.log(req.fingerprint)
})