防止window.WebSocket替换

时间:2017-06-27 02:49:37

标签: javascript

如何防止这样的事情

var realSocket = window.WebSocket;

class WebSocket {
    constructor(src) {
        console.log("binded...");

        this.ws = new realSocket(src);
        this.fakeMsgCb = () => {};
        this.ws.onmessage = (data) => this.msg(data);
    }

    set onopen(cb) {
        this.ws.onopen = cb;
    }

    set onclose(cb) {
        this.ws.onclose = cb;
    }

    msg(data) {
        console.log("incoming ->", data);
        this.fakeMsgCb(data);
    }

    send(data) {
        console.log("outgoing ->", data);
        this.ws.send(data);
    } 

    set onerror(cb) {
        this.ws.onerror = cb;
    }

    set onerror(cb) {
        this.ws.onerror = cb;
    }

    set onmessage(cb) {
        this.fakeMsgCb = cb;
    }

    get readyState() {
        return this.ws.readyState;
    }
}

window.WebSocket = WebSocket;

可以粘贴在控制台或浏览器用户脚本中,然后他们可以轻松记录数据?别担心,我知道我不能相信客户,也不要隐瞒任何安全问题或其他任何事情,但我只是想让它更难以阅读Incoming& amp;传出数据

0 个答案:

没有答案