access Websocket traffic from chrome extension

后端 未结 5 574
借酒劲吻你
借酒劲吻你 2021-01-31 06:07

There is a page (game), which communicate via WebSocket to the server. I can see the data (frames) in the Chrome Developer Tool. Is it possible to access / modify this communica

5条回答
  •  太阳男子
    2021-01-31 07:02

    I came across this question and tried solutions above, unfortunately the scripts in my target site still found WebSocket has been tampered and broke, which is bad.

    So I come up with my own solution:

    var ws = window.WebSocket;
    window.WebSocket = function(a,b){
    var ret = new ws(a,b);
    let handle = setInterval(function(){
                      if(ret.onmessage){
                         clearInterval(handle);
                         let o = ret.onmessage;
                         ret.onmessage = function(m){
                                           //do what your want to m
                                           o(m);
                                         };
                       }
                       },50);
                       return ret;
                  }
    

    If the site you want to inspect does use WebSocket, I will definitely assign to onmessage sometime after creating WebSocket object, just check it periodically and reassign it with your own function.

提交回复
热议问题