>Uncaught InvalidStateError: Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.(index):29 (anonymous function)

Código:

    function smConnect() {
        ws = new WebSocket('ws://127.0.0.1:1805/');
        delete ws.URL;
    
        ws.onopen = function(response) {
        };
    
        ws.onmessage = function(response) {
        };
    
        ws.onclose = function(response) {
        };
    
        ws.onerror = function(error) {
        };
    }
    
    smConnect();
    ws.send('message', 'hi');


O que pode ser?