Connecting to wss in node.js

I have a problem connecting to a certain game’s websocket. In python it connects without a problem, but in node.js I don’t want to connect anymore. Anyone know why?
Python code that works fine:

import websocket
import json
#websocket.enableTrace(True)
ws = websocket.WebSocket()
ws.connect("wss://unia.margonem.pl/ws-engine")
ws.send('{"g":"initlvl=1&&t=init","p":""}')
log = ws.recv()
print(format(log))

Node.js code that won’t work:

const WebSocket = require('ws');
const ws = new WebSocket("wss://unia.margonem.pl/ws-engine");
ws.onopen = function() {
    console.log('Połączono z serwerem.');

}
//ws.onerror = a => {
    //console.log(a)
    //return;
//};

ws.onclose = function() {
    console.log("Rozłączono")
    return;
};