-
Notifications
You must be signed in to change notification settings - Fork 293
qz-tray.js:768 Uncaught TypeError: Cannot read properties of undefined (reading '0') / ReactJS #1319
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
Comments
Please provide MINIMAL code to reproduce. Chances are you're calling |
the full code is may be complex because of Navigation, but for this part , I inspired from demo.qz.io
|
qz.security.setCertificatePromise((resolve) =>
fetch("qzSign/digital-certificate.txt", {
cache: "no-store",
headers: { "Content-Type": "text/plain" },
})
.then((data) => data.text())
.then((text) => resolve(text))
);
console.log(
"setCertificatePromise passée, on a le certif repetable de qztray"
);//this pass ok FYI, this var wrapped = fetch("qzSign/private-key.pem", {
cache: "no-store",
headers: { "Content-Type": "text/plain" },
});
console.log("private key : ", wrapped.text()); Same here,the return function (resolve, reject) {
try {
[...] Next, you're using try/catch, which is an anti-pattern when dealing with promises chains (they have natural support for this). If you prefer to use try/catch please change your code to use Here's the code, rewritten with proper promise chain support. qz.security.setCertificatePromise((resolve, reject) =>
fetch('qzSign/digital-certificate.txt2', {
cache: 'no-store',
headers: { 'Content-Type': 'text/plain' },
})
.then(data => {
if(data.ok) {
return data.text();
}
throw new Error(data.status);
})
.then(text => {
console.log("PASS: fetch('qzSign/digital-certificate.txt')");
resolve(text);
}).catch(err => {
console.error("FAIL: fetch('qzSign/digital-certificate.txt')", err);
reject(err);
})
);
qz.security.setSignatureAlgorithm("SHA512");
qz.security.setSignaturePromise(function (toSign) {
return function(resolve, reject) {
fetch('qzSign/private-key.pem2', {
cache: "no-store",
headers: { "Content-Type": "text/plain" },
})
.then(data => {
if(data.ok) {
return data.text();
}
throw new Error(data.status + " qzSign/private-key.pem");
})
.then(text => {
console.log("PASS: fetch('qzSign/private-key.pem')");
var pk = KEYUTIL.getKey(text);
var sig = new KJUR.crypto.Signature({ alg: "SHA512withRSA" });
sig.init(pk);
sig.updateString(toSign);
var hex = sig.sign();
console.log("DEBUG: \n\n" + stob64(hextorstr(hex)));
resolve(stob64(hextorstr(hex)));
})
.catch(err => {
console.error("A problem occured while signing", err);
reject(err);
})
};
}); // Since 2.1 - // causes the trouble "semver is undefined" (valeur à underfined sur FF), ou sur Chrome : Cannot read properties of undefined (reading '0') I still cannot reproduce this error. Please provide a minimal reproducible code example. |
hi, If I remove the line that block : I have only in the console the error :
my code is so (small correction in reject, .pem instead of .pem2 : qz.security.setCertificatePromise((resolve) =>
fetch("qzSign/digital-certificate.txt", {
cache: "no-store",
headers: { "Content-Type": "text/plain" },
})
.then((data) => {
if (data.ok) {
return data.text();
}
throw new Error(data.status);
})
.then((text) => {
console.log("PASS: fetch('qzSign/digital-certificate.txt')");
resolve(text);
})
.catch((err) => {
console.error("FAIL: fetch('qzSign/digital-certificate.txt')", err);
throw err;
})
);
//qz.security.setSignatureAlgorithm("SHA512"); // Since 2.1
qz.security.setSignaturePromise(function (toSign) {
return function (resolve, reject) {
fetch("qzSign/private-key.pem", {
cache: "no-store",
headers: { "Content-Type": "text/plain" },
})
.then((data) => {
if (data.ok) {
return data.text();
}
throw new Error(data.status + " qzSign/private-key.pem");
})
.then((text) => {
console.log("PASS: fetch('qzSign/private-key.pem')");
var pk = KEYUTIL.getKey(text);
var sig = new KJUR.crypto.Signature({ alg: "SHA512withRSA" }); // Use "SHA1withRSA" for QZ Tray 2.0 and older
sig.init(pk);
sig.updateString(toSign);
var hex = sig.sign();
console.log("DEBUG: \n\n" + stob64(hextorstr(hex)));
resolve(stob64(hextorstr(hex)));
})
.catch((err) => {
console.error("A problem occured while signing", err);
reject(err);
});
};
}); I do understand the use of the line removed but do not understand why it is sending an error alone. Do we have both the same lib version of QZ ? |
I do not believe this statement to be true. The error that you had before was:
Now the error that you have is:
...
This error is not generated by QZ, it's generated by the crypto library (jsrsasign). Is there a chance you have a password protected private key? In our experience, that's not supported with jsrsasign. |
ah yes it is ! I will remove that, and tell you , thanks ! |
@Productivix thanks for sharing your environment with me. I've filed a dedicated bug report for the issue you've discovered. A workaround was to ensure |
It works if the 2 conditions are respected :
So the ReactJs structure of App.js is :
hope this reseach will help you all . |
@Productivix thanks, I'm sure this will help others. In the meantime, I'll try to harden the |
@Productivix please forgive my bad memory, this issue is already resolved on master. #1302. |
Rem : of course the 2 files qzSign/digital-certificate.txt & qzSign/private-key.pem are stored under public/qzSign in React Project (it is not the best practice for secrets, I agree) |
hi,
in ReactJS,
at line (95) :
qz.security.setSignatureAlgorithm("SHA512"); // Since 2.1 -
I get the error on Chrome :
or on FireFox :
I have the lib
"qz-tray": "^2.2.4",
do you know where it comes from please ?
thanks
The text was updated successfully, but these errors were encountered: