qzind / tray

Browser plugin for sending documents and raw commands to a printer or attached device.
https://qz.io
Other
853 stars 277 forks source link

cant use websocket.connect() it actually dont connect #1306

Open BrunolourencoLucas opened 4 days ago

BrunolourencoLucas commented 4 days ago

Hello everyone, I'm new to using QZ Tray, and I'm having an issue. Unfortunately, I can't establish a connection with QZ Tray. Every time I use websocket.connect() and try to use other API functions like printing, it shows that I don't have an established connection with QZ Tray. After using websocket.connect() and then websocket.isActive, it returns false. However, in the application, it shows that a connection was established. If I reload QZ Tray from the sidebar, it shows the "closed connection" log. If someone could help me, I would appreciate it.

<script src="/diversos/js/assets/nodes/inputmask/dist/jquery.inputmask.js"></script>
<script src="/diversos/js/assets/nodes/qz-tray/qz-tray.js"></script>
<script src="/diversos/js/assets/nodes/qz-tray/sign-message.js"></script>
<script src="/diversos/js/assets/nodes/promise-polyfill/lib/polyfill.js"></script>
<script src="/diversos/js/assets/nodes/promise-polyfill/lib/padstart-pollyfill.js"></script>
<script src="/diversos/js/assets/nodes/promise-polyfill/lib/array-from-pollyfill.js"></script>
<script>

qz.security.setCertificatePromise(function(resolve, reject) {
    /* ... */ });
qz.security.setSignatureAlgorithm("SHA512"); // Since 2.1
qz.websocket.connect().then(() => {
    console.log(qz.websocket.isActive());
    return qz.printers.find("Microsoft Print to PDF")
}).then((printers) => {
    var config = qz.configs.create(printers);  // Create a default config for the found printer
    var data = [{
        type: 'pixel',
        format: 'html',
        flavor: 'file', // or 'plain' if the data is raw HTML
        data: '<h1>hello world</h1>'
    }];
    return qz.print(config, data);
});
</script>
Possible Unhandled Promise Rejection: Error: A connection to QZ has not been established yet
    at Object.assertActive (qz-tray.js:799:23)
    at Object.versionCompare (qz-tray.js:766:31)
    at Object.data (qz-tray.js:863:30)
    at Object.print (qz-tray.js:1645:32)
    at imprimirDigitag :489:19
    at polyfill.js:169:13

print1 print2

The flavor is actually set to plain. I printed it before and tested it on plain, but I still get the error.

BrunolourencoLucas commented 4 days ago

After three days of searching, testing, and crying, I decided to make the issue public. Just minutes later, I found the problem. It seems there is a conflict between QZ Tray and this plugin: https://github.com/CodeByZach/pace.

tresf commented 4 days ago

@BrunolourencoLucas thanks for filing this bug report. I believe that your actual error stems from the polyfill library that you are using, but I'm not entirely certain as we use promises heavily in our library, and are compatible with 3rd party promise libraries.

Since versionCompare is part of the backtrace, this may be a duplicate of #1301, which is caused by a race condition in our JavaScript library. Can you test to see if the qz-tray.js from our master branch fixes this? I've linked in in the bug report,

BrunolourencoLucas commented 3 days ago

I have conducted some tests, and it seems that the issue is not related to #1301. The master branch does not fix it.

tresf commented 2 days ago

I have conducted some tests, and it seems that the issue is not related to #1301. The master branch does not fix it.

I tested with promise-polyfill@8.3.0 and the reported symptom/bug does not occur.

Since the sample code does not reference exactly which JS libraries you are using, can you please zip up all dependencies in the linked example and attach? That way we can dive deeper on which one's conflicting with QZ Tray.