Comments (9)
You can create a component that you can import and use dynamically
The component:
import { ClientJS } from 'clientjs'
import { useEffect } from 'react';
export default function ClientJsComponent({ setFingerPrint }) {
useEffect(() => {
const client = new ClientJS();
const fingerprint = client.getFingerprint();
setFingerPrint(fingerprint);
}, [])
return null
}
How to use it
import { useState } from 'react';
import dynamic from 'next/dynamic'
const ClientJs = dynamic(() => import('./components/ClientJs'), { ssr: false });
export default function Page () {
const [fingerPrint, setFingerPrint] = useState()
return (
<>
{fingerPrint}
<ClientJs setFingerPrint={setFingerPrint} />
</>
)
}
Maybe it's not elegant, but it might do it.
Another option is to copy the ClientJs min script to public, load it with <Script src="/ClientJS.min.js" onLoad={doSomething} />
and run a functión when it's ready
from clientjs.
Here is the thing, as I understand it, the lib is doing something on require
and not on initialization
by constructor.
Here is a working workaround
try {
// This is not working anyway else, it performs an action on require which is
// throwing error build time
const client = require('clientjs')
const browser = new client.ClientJS()
// The rest of the usage
}
catch () {
// Do nothing
}
from clientjs.
Didn't work for me,
Falling back to fingerprintJs.
Thanks for the quick response.
from clientjs.
You can use the dist/client.base.min.js
as described in the docs. This should work without executing any code upon a require call/import. It also has the benefit of being much smaller without losing any functionality on modern browsers.
from clientjs.
Here is the thing, as I understand it, the lib is doing something on
require
and not oninitialization
by constructor. Here is a working workaroundtry { // This is not working anyway else, it performs an action on require which is // throwing error build time const client = require('clientjs') const browser = new client.ClientJS() // The rest of the usage } catch () { // Do nothing }
thanks this code works for me. It solves my "ReferenceError: navigator is not defined" error when I try to build the next.js application. this is how I implemented it... maybe it can help someone...
`
const onFinish = async (values: ILogin) => {
try {
const ClientJs = require("clientjs");
const client = new ClientJs.ClientJS();
const fingerprint = client?.getBrowserData();
const deviceId = client?.getFingerprint();
const data = {
...values,
devicesInfo: {
devicesId: deviceId?.toString(),
devicesModel: fingerprint?.device?.model,
devicesType: fingerprint?.device?.type,
devicesVendor: fingerprint?.device?.vendor,
browserName: fingerprint?.browser?.name,
browserVersion: fingerprint?.browser?.version,
engineName: fingerprint?.engine?.name,
engineVersion: fingerprint?.engine?.version,
osName: fingerprint?.os?.name,
osVersion: fingerprint?.os?.version,
cpuArchitecture: fingerprint?.cpu?.architecture,
agentClient: fingerprint?.ua,
},
};
const response = await userLogin({ ...data }).unwrap();
if (response?.data?.accessToken) {
storeUserInfo({ accessToken: response?.data?.accessToken });
message.success(`${response?.message}`);
if (isLoading) {
return <LoadingPage />;
}
const { role } = getUserInfo() as IJwtDecoded;
router.push(`/${role}`);
}
} catch (error: any) {
if (error?.data?.message) {
message.error(error?.data?.message);
}
}
};
`
from clientjs.
Faced the same issue, any help would be appreciated.
from clientjs.
You can use the
dist/client.base.min.js
as described in the docs. This should work without executing any code upon a require call/import. It also has the benefit of being much smaller without losing any functionality on modern browsers.
thanks!! I have tried and succeeded.
from clientjs.
@BendingBender The problem with including a "pre-minified" JS code is that there's no solid way to verify whether the source and minified version match. This could be a serious risk for certain websites that deal with PII and financial data. Most of today's fav frameworks are webpack/vite based, and they have configs for minifications.
Not saying that the minified files in dist do anything malicious.
from clientjs.
same issue
from clientjs.
Related Issues (20)
- Compatibility problem with Vue HOT 3
- On the same computer, on the same browser client.getFonts() Run it twice and the result is different in fireFox
- Vulnerable ua-parser-js version HOT 1
- Congratulations!!! I am glad you are back to update and improve this amazing and useful script.
- Advice of data point permanence HOT 1
- osVersion is Windows 11, But detecting 10 HOT 3
- Server Error ReferenceError: navigator is not defined HOT 6
- Generating different fingerprint id for different browser issue HOT 4
- why getFingerprint show other Digital fingerprints based on same device/browser in NextJS
- remove dep on globalthis HOT 1
- it needs an update to check incognito Mode
- e[t].toUpperCase is not a function
- Is clientjs an idled project? HOT 8
- Missing copyright notice
- The examples provided in the documentation may generate errors
- The GetFingerprint() method blocks the main thread
- Update ua-parser-js version
- ClientJS don't support Windows 11 ?
- Noticed something weird with Messenger navigator, any Ideas ? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clientjs.