it should still fix some issue I found the cause of my issue and would like to share it here for anybody looking for an answer. It turned out to be an authorization issue. My scripts were used in couple of different projects, but each one of them had the same name. Adding to that some test spreadsheets I made to test some solutions, each of them again using script projects with the same name eventually led to my account authorizing ~ 15 scripts of the same name to use my google account. This made google confused and resulted in these scripts working only one at a time. I fixed this by removing all registered triggers and removing the authorization for them from my google account. I then created separate projects, each named differently, and pasted my functions in them. Now all my functions work properly, regardless of whether they are used withing the same script file or not.
How can I make sure a Websocket does not open before attaching an onopen handler?
var socket = new WebSocket('ws://localhost:8080');