Description
I am trying to print PDF files that I receive via URL, but I am encountering an error.
qz-tray.js:768 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '0')
at Object.versionCompare (qz-tray.js:768:1)
at Object.data (qz-tray.js:863:1)
at Object.print (qz-tray.js:1645:1)
at reader.onloadend (EtiquetasIntelipostPage.vue:339:1)
Whenever it reaches the print part, this error occurs.
Here is how I connect to the WebSocket and sign the requests:
<q-btn
unelevated
color="primary"
:disable="!selectedDevice"
label="Imprimir"
class="q-ml-xl flex flex-rigth"
@click="getNotafiscal(filtros)"
/>
const getNotafiscal = (filtros = {}) => {
notafiscalService.getIntelipost(filtros).then((response) => {
if (response.status === 200) {
playSound('success')
printLabel(response.data.data.content.label_url)
}
}).catch(errors => {
$q.notify({
color: 'warning',
message: GetErrorMessage(errors)
})
})
}
const printLabel = async (url) => {
console.log('URL do PDF:', url)
try {
if (!isQZConnected.value) {
await connectQZTray()
}
const response = await fetch(url)
if (!response.ok) throw new Error('Erro ao baixar etiqueta')
const blob = await response.blob()
console.log('Blob do arquivo:', blob)
const reader = new FileReader()
reader.onloadend = async () => {
if (!reader.result) {
console.error('Erro: O FileReader não conseguiu ler o arquivo.')
return
}
const base64Data = reader.result.split(',')[1]
console.log('Tamanho do Base64:', base64Data.length)
if (!base64Data || base64Data.length < 1000) {
console.error('Erro: Base64 gerado é muito pequeno, pode estar corrompido.')
return
}
if (!selectedDevice.value) {
console.error('Nenhuma impressora foi selecionada!')
return
}
const version = await qz.api.getVersion()
console.log('QZ Tray versão:', version)
// 🔹 Configuração de impressão
const config = qz.configs.create(selectedDevice.value, {
margins: 0,
scaleContent: false,
orientation: 'portrait'
})
// 🔹 Opções testadas
const data = [{
type: 'pixel',
format: 'pdf',
flavor: 'base64',
data: base64Data
}]
console.log('Enviando para a impressora...')
console.log('QZ Tray está ativo?', qz.websocket.isActive())
await qz.print(config, data)
.then(() => console.log('Etiqueta enviada para a impressora!'))
.catch(error => console.error('Erro ao imprimir etiqueta:', error))
}
reader.readAsDataURL(blob) // Converte para Base64
} catch (error) {
console.error('Erro ao imprimir etiqueta:', error)
}
}
Activity
tresf commentedon Mar 13, 2025
Can you try to use the qz-tray.js version from our master branch and see if it goes away?
robertoedu commentedon Mar 13, 2025
Just copy and paste the qz-tray-js in node-modules?
tresf commentedon Mar 13, 2025
Yes... I think this is a duplicate of #1320 #1301
robertoedu commentedon Mar 13, 2025
Well, that message is gone, but now my setCertificatePromise and setSignaturePromise are not working.
robertoedu commentedon Mar 13, 2025
I am fetching the certificate and trying to connect to the WebSocket, but after connecting, when I try to sign it as described in the documentation, the signing process does not occur, and an error is returned.
qz-tray.js:768
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '0')
at Object.versionCompare (qz-tray.js:768:1)
at Object.data (qz-tray.js:863:1)
at Object.print (qz-tray.js:1646:1)
at reader.onloadend (EtiquetasIntelipostPage.vue:338:1)
tresf commentedon Mar 13, 2025
It is expected that
setCertificatePromise
andsetSignaturePromise
are passed a promise-style function(resolve, reject) =>
however your function never callsresolve()
orreject()
.This code is untested, but these are the mistakes that I have found...
tresf commentedon Mar 18, 2025
Closing to due lack of response. Please reopen if you believe this was closed in error.