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);