-
Notifications
You must be signed in to change notification settings - Fork 293
Cannot read property 'split' of undefined #538
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
Can you please provide the steps necessary to reproduce these errors?
|
QZ Tray v2.0.11-1 I haven't isolated the code that's causing the problem yet, but will post when I do. |
@pelargir thanks. It's probably an overlooked entry in our |
@pelargir checking in to see if you can provide some sample code, we'd love to fix this. If we don't see the code in another week or so, we'll close this out, but we'd happily re-open it when the code is provided. |
Closing for now. I definitely won't be able to provide anything within a week. |
I've tracked the problem down to compatible: function(printData) {
var semver = _qz.websocket.connection.version.split(/[.-]/g);
... The split method is being called on
Any idea why the version would be null? |
That should only be null if you're not connected (the value is filled on successful connection). |
We did see this error for some customers and it was caused by a behavior change in the WebSocket as described here: #524 That fix was Java related, as the WebSocket would throw an unrecoverable error with certain browsers (Mostly Microsoft Edge), but that should be fixed with 2.1.0 proper. |
Closing as fixed for now, since we can't reproduce and all previous errors were fixed in code. Please request a re-open if steps to reproduce can be provided. |
This is no longer happening when using qz-tray.js v2.1.1 with QZ Tray 2.0.12 client. |
@pelargir thanks for the follow up, much appreciated. |
Spoke too soon. This is actually still happening, albeit with a slightly different error message. The problem still seems to center around receiving an unexpected null QZ Tray semver. I'll open a separate issue with additional information since the error is different. |
Although the error has technically changed, I expect the underlying cause to be identical. We're always fine with fresh bug reports, it helps others/search engines find the problem quicker. :D |
Thanks for your patience. I won't be opening a new issue after all. I fixed the new error by updating our print options from 2.0 to the 2.1 syntax. I also updated QZ Tray client to 2.1. I had thought qz-tray.js 2.1 could still operate nicely with QZ Tray client 2.0, but in our situation that didn't seem to be happening. It's working now though. 👍 |
|
Sure, I'll see what I can put together for you regarding the version incompatibility we observed. Incidentally, after deploying our most recent v2.1 syntax changes to our production environment, the "undefined" version error came back again. We finally switched to establishing our websocket connection on page load (instead of immediately before attempting to print as it had been before) and the problem went away. It seems like the websocket connection was not being opened quickly enough and as a result, when we tried to print, the QZ Tray version was coming back undefined. Subsequent attempts to print (without reloading the page) worked since the connection had certainly been established by that point. This was the code we had been using when we saw the "undefined" version errors: qz.websocket.connect().then(sendPrintJob).catch(reject) This was what ended up fixing the problem: qz.websocket.connect()
// other stuff in between
sendPrintJob() When a websocket connection is first established, is there a delay during which API calls would fail (i.e. the QZ Tray version cannot be successfully retrieved)? If so, I would have thought the promise chain above would not have allowed |
Correct, I'd expect this to work. Testing locally, this is fine: qz.websocket.connect().then(
()=> qz.printers.getDefault()
).then(
(printer)=> qz.print(qz.configs.create(printer), [ { type: 'pixel', format: 'html', flavor: 'file', data: 'https://qz.io/about' } ])
).catch(
(err) => console.error(err)
); Note, there's some implicit stuff happening above, |
As most race conditions are -- this one was hard to reproduce. Further examining the code, I believe the connection should wait until getVersion() has completed first. |
Here's our code: if (qz.websocket.isActive()) {
qz.print(config, data).then(() => {
resolve()
}).catch(reject)
} else {
qz.websocket.connect().then(() => {
qz.print(config, data)
}).then(() => {
resolve()
}).catch(reject)
} |
2.1.0 is tagged as pre-release so I assume it's not production-ready yet. We attempted to upgrade and immediately began getting these JS errors which are not present in the prior version:
The text was updated successfully, but these errors were encountered: