5

I'm fairly new to javascript and I've been looking through script nearly all day to see if there is a way to sniff websocket traffic for debugging and research or simple replace websocket with my own.

I've tried filtering with Chrome and used fiddler and everything somehow the traffic is being hidden. Wireshark seems to grab something that neither can find but it's jibberish at least to me whose not to familiar with hex.

However I would really like to know is it possible to extend something like Websocket in javascript so that say when it's created using something like Greasemonkey I could "extend" it so that it continues to do what it's suppose to do but also does additional work.

For example is it possible to extend the following websocket in say Greasemonkey so that onMessage(evt) it continues to write to screen but then I could add an alert(message);?? This would be more desirable then say watching the traffic. Note I cannot change the source files.

Google Chrome is not identifying the sites websocket for games like dragons of atlantis the actions are ajax posts but the chats are a websocket which can be found in the flash parameters.

<!DOCTYPE html>

 <meta charset="utf-8" />

<title>WebSocket Test</title>

<script language="javascript" type="text/javascript">

  var wsUri = "ws://echo.websocket.org/";
  var output;

  function init()
  {
    output = document.getElementById("output");
    testWebSocket();
  }

  function testWebSocket()
  {
    websocket = new WebSocket(wsUri);
    websocket.onopen = function(evt) { onOpen(evt) };
    websocket.onclose = function(evt) { onClose(evt) };
    websocket.onmessage = function(evt) { onMessage(evt) };
    websocket.onerror = function(evt) { onError(evt) };
  }

  function onOpen(evt)
  {
    writeToScreen("CONNECTED");
    doSend("WebSocket rocks");
  }

  function onClose(evt)
  {
    writeToScreen("DISCONNECTED");

  }


  function onMessage(evt)

  {

    writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data+'</span>');

    websocket.close();

  }



  function onError(evt)

  {

    writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);

  }



  function doSend(message)

  {

    writeToScreen("SENT: " + message); 

    websocket.send(message);

  }


  function writeToScreen(message)

  {

    var pre = document.createElement("p");

    pre.style.wordWrap = "break-word";

    pre.innerHTML = message;

    output.appendChild(pre);

  }


  window.addEventListener("load", init, false);


</script>


<h2>WebSocket Test</h2>


<div id="output"></div>


</html>

I found this in stackoverflow would I just replace date with websocket??

Date = function (Date) { return function () { var date = clockwork.instantiate(Date, arguments); var args = arguments.length; var arg = arguments[0]; if ((args === 3 || args == 6) && arg < 100 && arg >= 0) date.setFullYear(arg); return date; } }(Date);
casperOne
  • 73,706
  • 19
  • 184
  • 253
  • [Chrome has better tools for seeing Websocket traffic](http://stackoverflow.com/a/12305398/331508). Using Greasemonkey, you could *probably* intercept a page's Websockets by overriding the constructor before the page loads. (Haven't tried it) – Brock Adams Mar 16 '13 at 08:01
  • Jacek I thank you for the response however this is not a duplicate. Yes I am curious about sniffing the traffic however I would also like to know if it's possible to extend the websocket in javascript so that it continues doing what it should but also do extra tasks. – JavaIntermediate Mar 21 '13 at 07:57
  • @AlanHergert First, we don't ask the person asking the question when closing, it just doesn't scale. Second, if you don't feel that your question should be closed for any reason, you should a) flag for moderator attention, b) post to [meta] or c) comment @ a moderator. What you do **not** do is edit your post to include meta commentary. Please refrain from doing that in the future. – casperOne Mar 22 '13 at 13:58
  • @casperOne if I ask the question differently or provide a different wording should I continue to edit this or is there a way to replace it or can I post a new one to encourage a response since this question as it is has provided little but a wrestling match for me. Thank you for your commitment in keeping the community active and providing some direction on improving my experience – JavaIntermediate Mar 23 '13 at 09:14

0 Answers0