Reputation: 2957
How can a greasemonkey script / Chrome's user-script intercept a running websocket communication?
My goal is to have additional statistics for a in-browser game
Upvotes: 11
Views: 5410
Reputation: 11
Credit to: https://github.com/Cryoscalpel
Not sure if this works in all ws games but you can create a proxy websocket message logger.
WebSocket.prototype.send = new Proxy(WebSocket.prototype.send, {
apply: function(target, scope, args) {
if(typeof(args[0]) === 'string') {
let json = JSON.parse(args[0]);
console.log(json)
}
let data = target.apply(scope, args);
return data;
}
})
Upvotes: 1
Reputation: 6736
You may use Firefox, then add the Firebug module then add & use websocket-monitor module to monitor websocket.
If you want to hook websocket from javascript you may also use wshook.
Upvotes: 4