Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function debugify_content_script(){
- console.log('debugify content script running');
- var nativeWebSocket = window.WebSocket;
- var requests = window.requestLog = {};
- var WebSocket = window.WebSocket = function(uri) {
- console.log('new WebSocket created', uri);
- this.websocket = new nativeWebSocket(uri);
- this.websocket.onopen = this.onOpen.bind(this);
- this.websocket.onmessage = this.onMessage.bind(this);
- this.listeners = {onmessage: null, onopen: null};
- if (!window._openWebSockets) window._openWebSockets = [];
- window._openWebSockets.push(this);
- };
- WebSocket.prototype.send = function(msg) {
- console.log('>>', msg);
- this.websocket.send.apply(this.websocket, arguments);
- }
- WebSocket.prototype.onOpen = function(e){
- console.log('OPEN', arguments);
- this.listeners.onopen(e);
- }
- WebSocket.prototype.onMessage = function(e){
- console.log('<<', e.data);
- this.listeners.onmessage(e);
- }
- Object.defineProperty(WebSocket.prototype, 'readyState', {
- get: function() {
- return this.websocket.readyState;
- }
- });
- Object.defineProperty(WebSocket.prototype, 'onopen', {
- get: function() {
- return this.listeners.onopen;
- },
- set: function(fn) {
- this.listeners.onopen = fn;
- }
- });
- Object.defineProperty(WebSocket.prototype, 'onclose', {
- get: function() {
- return this.websocket.onclose;
- },
- set: function(fn) {
- this.websocket.onclose = fn;
- }
- });
- Object.defineProperty(WebSocket.prototype, 'onmessage', {
- get: function() {
- return this.listeners.onmessage;
- },
- set: function(fn) {
- this.listeners.onmessage = fn;
- }
- });
- Object.defineProperty(WebSocket.prototype, 'onerror', {
- get: function() {
- return this.websocket.onerror;
- },
- set: function(fn) {
- this.websocket.onerror = fn;
- }
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement