Created
July 19, 2021 14:31
-
-
Save burstfreeze/c994177175cf8b93af7772a72dabad03 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
customSocketX = 0; | |
function printEvent(event) { | |
console.log(event) | |
var eventArray = new Uint8Array(event) | |
console.log(String.fromCharCode.apply(null, eventArray)) | |
} | |
(function() { //https://stackoverflow.com/a/62839570/5682822 | |
var OrigWebSocket = window.WebSocket; | |
var callWebSocket = OrigWebSocket.apply.bind(OrigWebSocket); | |
var wsAddListener = OrigWebSocket.prototype.addEventListener; | |
wsAddListener = wsAddListener.call.bind(wsAddListener); | |
window.WebSocket = function WebSocket(url, protocols) { | |
var ws; | |
if (!(this instanceof WebSocket)) { | |
// Called without 'new' (browsers will throw an error). | |
ws = callWebSocket(this, arguments); | |
} else if (arguments.length === 1) { | |
ws = new OrigWebSocket(url); | |
} else if (arguments.length >= 2) { | |
ws = new OrigWebSocket(url,protocols); | |
} else { | |
// No arguments (browsers will throw an error) | |
ws = new OrigWebSocket(); | |
} | |
wsAddListener(ws, 'error', function(event) { | |
console.log("WS EVENT ERROR") | |
console.log(event) | |
}); | |
wsAddListener(ws, 'close', function(event) { | |
console.log("WS EVENT CLOSE") | |
console.log(event) | |
}); | |
wsAddListener(ws, 'open', function(event) { | |
console.log("WS EVENT OPEN") | |
console.log(event) | |
}); | |
wsAddListener(ws, 'message', function(event) { | |
console.log("\n\nRECEIVED:") | |
printEvent(event.data) | |
}); | |
console.log("\n\n)))))))\nNEW SOCKET CREATED") | |
console.log(ws) | |
customSocketX = ws; | |
console.log(customSocketX) | |
return ws; | |
} | |
.bind(); | |
window.WebSocket.prototype = OrigWebSocket.prototype; | |
window.WebSocket.prototype.constructor = window.WebSocket; | |
var wsSend = OrigWebSocket.prototype.send; | |
wsSend = wsSend.apply.bind(wsSend); | |
OrigWebSocket.prototype.send = function(data) { | |
console.log("\n\nSENT: "); | |
printEvent(data) | |
console.log("arguments: ",arguments) | |
return wsSend(this, arguments); | |
} | |
; | |
} | |
)(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment