add global redirection example

This commit is contained in:
James Feng Cao 2024-03-17 10:36:18 +08:00
parent 68fa9617be
commit 22277c08c3
11 changed files with 35 additions and 21 deletions

View file

@ -0,0 +1,13 @@
window.WebSocketOriginal = window.WebSocket;
(function () {
function CustomWebSocket(url) {
const ws = new window.WebSocketOriginal(url);
Object.getOwnPropertyNames(window.WebSocket.prototype).forEach(methodName => {
if (methodName !== 'constructor') {
CustomWebSocket.prototype[methodName] = ws[methodName].bind(ws);
}
});
}
window.WebSocket = CustomWebSocket;
})();
t