-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not working on nextjs #140
Comments
Faced the same issue, any help would be appreciated. |
Here is the thing, as I understand it, the lib is doing something on
|
Didn't work for me, |
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 |
You can use the |
thanks!! I have tried and succeeded. |
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... `
}; |
@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. |
same issue |
same issue, clientjs should not access navigate during initialization. |
The lib is throwing the following error when next build is ran
ReferenceError: navigator is not defined
at Object.getBrowser (C:\projects\web-ssd-cms-api-bakcend\web-ssd-website-frontend\node_modules\clientjs\src\vendor\deployJava.js:1150:21)
at Object.writePluginTag (C:\projects\web-ssd-cms-api-bakcend\web-ssd-website-frontend\node_modules\clientjs\src\vendor\deployJava.js:1365:24)
at Object. (C:\projects\web-ssd-cms-api-bakcend\web-ssd-website-frontend\node_modules\clientjs\src\vendor\deployJava.js:1423:12)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object. (C:\projects\web-ssd-cms-api-bakcend\web-ssd-website-frontend\node_modules\clientjs\src\modules\java-detection.js:3:18) {
type: 'ReferenceError'
}
Even if one puts try catch on the block it still does this, because the issue is in import method. It tries to do something with navigator import time, but I believe it should do anything only when
new ClientJS
is calledThe text was updated successfully, but these errors were encountered: