1

I'm using the solution found here (How to change url on Chromium kiosk mode via ssh) using node.js that is called from a bash script and it works great to change the current URL in chrome. The problem is that the node.js script hangs after it does it's thing. In the script, they say use promise-ws to exit the program then use process.exit().

When I use process.exit() without the promise, the script closes too quickly before passing the argument to chrome. I am new to js and need some help coding the promise.

Thanks for any suggestions.

  • Are you looking for something smart that waits for a response, or something that just waits a certain amount of time (for example, 5 seconds, no matter what) – Samathingamajig Jul 11 '22 at 17:54
  • Did you use `promise-ws` or not? – Bergi Jul 11 '22 at 17:55
  • I just want it to wait long enough for the URL the make the change. When I run the script as-is, it works but the node.js script hangs and never goes back to my bash script that is continuing to do things. When I add process.exit(), the node.js script runs and the bash script continues to run but the URL never gets changed – John Proctor Jul 11 '22 at 18:00
  • I don't know how to use promise-ws within this script. – John Proctor Jul 11 '22 at 18:01
  • @JohnProctor but is that something you can wait a certain amount of seconds for, or do you *need* it to detect exactly when it changes the URL successfully? – Samathingamajig Jul 11 '22 at 18:11
  • @Samathingamajig It could probably wait but I would prefer it to be smarter and just exit once it changes the URL. I am assuming the author of the script meant for a promise to be used since they put that in a comment but I have never used a promise before. – John Proctor Jul 11 '22 at 18:15
  • @JohnProctor I think the author of the script literally meant you should use the [`promise-ws` package](https://www.npmjs.com/package/promise-ws) instead of the `ws` one. Alternatively, you can just use [the `callback` parameter to `wsChrome.send()`](https://github.com/websockets/ws/blob/master/doc/ws.md#websocketsenddata-options-callback). – Bergi Jul 11 '22 at 18:21
  • Alright, that makes sense. If I change the beginning of the script to require("promise-ws") I get an error that says WebSocket is not a constructor. Forgive the ignorance, but do I need to change more in the script to properly use promise-ws? promise-ws is installed. – John Proctor Jul 11 '22 at 18:31
  • It seems you have to use `await WebSocket.create(wsUrl)` instead of `new WebSocket(wsUrl)`. The benefit would be that you don't have to wait for the `open` event either. But really, if you're new to this, I'd recommend just passing a callback (`wsChrome.send(JSON.stringify(dataChangeUrl), () => { process.exit(); })`) and keep using the `ws` package – Bergi Jul 11 '22 at 18:35
  • OMG it works!!!! that callback was it! Thank you so much @Bergi. – John Proctor Jul 11 '22 at 18:41

0 Answers0