Advertisement
sentero-esp12

Untitled

Nov 29th, 2021 (edited)
863
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This shows that Lichess's frontend discards illegal moves. Run this script in Tampermonkey and set a breakpoint to the '// outcoming websockets' line. Try to make an illegal move. The line won't be reached, because Lichess discards illegal moves. Try to make a legal move, and the line will be reached.
  2.  
  3. // ==UserScript==
  4. // @name         Check WebSockets
  5. // @namespace    http://tampermonkey.net/
  6. // @version      0.1
  7. // @match        https://lichess.org/*
  8. // @icon         https://www.google.com/s2/favicons?domain=lichess.org
  9. // @grant        none
  10. // @run-at       document-start
  11. // ==/UserScript==
  12.  
  13. console.log('script to check websockets');
  14.  
  15. (function () {
  16.       //to get the move that has been sent by the client, https://stackoverflow.com/a/31182643/10364842
  17.       var OrigWebSocket = window.WebSocket;
  18.       var callWebSocket = OrigWebSocket.apply.bind(OrigWebSocket);
  19.       var wsAddListener = OrigWebSocket.prototype.addEventListener;
  20.       wsAddListener = wsAddListener.call.bind(wsAddListener);
  21.       window.WebSocket = function WebSocket(url, protocols) {
  22.         var ws;
  23.         if (!(this instanceof WebSocket)) {
  24.           // Called without 'new' (browsers will throw an error).
  25.           ws = callWebSocket(this, arguments);
  26.         } else if (arguments.length === 1) {
  27.           ws = new OrigWebSocket(url);
  28.         } else if (arguments.length >= 2) {
  29.           ws = new OrigWebSocket(url, protocols);
  30.         } else {
  31.           // No arguments (browsers will throw an error)
  32.           ws = new OrigWebSocket();
  33.         }
  34.         wsAddListener(ws, 'message', function (event) {
  35.           // TODO: Do something with event.data (received data) if you wish.
  36.           console.log(event)
  37.         });
  38.         return ws;
  39.       }.bind();
  40.       window.WebSocket.prototype = OrigWebSocket.prototype;
  41.       window.WebSocket.prototype.constructor = window.WebSocket;
  42.  
  43.       var wsSend = OrigWebSocket.prototype.send;
  44.       wsSend = wsSend.apply.bind(wsSend);
  45.       OrigWebSocket.prototype.send = function (data) {
  46.         // TODO: Do something with the sent data if you wish.
  47.         if (data !== null && data !== 'null') {
  48.           // outcoming websockets
  49.           console.log(data);
  50.           debugger;
  51.         }
  52.         return wsSend(this, arguments);
  53.       };
  54.     })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement