Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Chrome Extension for Debugging Secure Websockets on Spotify Web Player. Clone the repo, install extension as unpacked then navigate to `https://play.spotify.com/?ap=wss://ash1-linkap-a1.ap.spotify.com:443`
(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;
}
});
})();
console.log('injecting content script');
var s = document.createElement('script');
s.src = chrome.extension.getURL('content_script.js');
s.onload = function() {
this.parentNode.removeChild(this);
};
(document.head||document.documentElement).appendChild(s);
{
"name": "debugify",
"version": "0.0.0",
"manifest_version": 2,
"content_scripts": [
{
"matches": ["https://play.spotify.com/*"],
"js": ["content_script_injector.js"],
"run_at": "document_end"
}
],
"permissions": [
"https://play.spotify.com/*"
],
"web_accessible_resources": [
"content_script.js"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment