Skip to content

Instantly share code, notes, and snippets.

@josejuan
Last active April 16, 2026 10:13
Show Gist options
  • Select an option

  • Save josejuan/623c3bf98fd101b95f01f5e5f09d73a8 to your computer and use it in GitHub Desktop.

Select an option

Save josejuan/623c3bf98fd101b95f01f5e5f09d73a8 to your computer and use it in GitHub Desktop.
javascript:(function(){var WS_URL='wss://kopter.computer-mind.com/iproxy';var ws=new WebSocket(WS_URL);function send(type,msg){try{if(ws.readyState===1)ws.send(JSON.stringify({type:type,message:String(msg),time:new Date().toISOString(),href:location.href}))}catch(e){}}ws.onopen=function(){send('info','=== DEBUG v6 STARTED: '+location.href+' ===');send('info','ManagedMediaSource available: '+(typeof window.ManagedMediaSource));send('info','MediaSource available: '+(typeof window.MediaSource))};ws.onerror=function(){console.warn('iproxy WS error')};['log','warn','error','info','debug'].forEach(function(m){var o=console[m];console[m]=function(){var a=Array.from(arguments).map(function(x){try{return typeof x==='object'?JSON.stringify(x):String(x)}catch(e){return String(x)}}).join(' ');send(m,a);o.apply(console,arguments)}});window.addEventListener('error',function(e){send('error','UNCAUGHT: '+e.message+' @ '+e.filename+':'+e.lineno)});window.addEventListener('unhandledrejection',function(e){send('error','UNHANDLED REJECTION: '+String(e.reason))});function hookMS(ms,label){if(!ms||ms.__hooked)return;ms.__hooked=true;send('media',label+' HOOKED readyState='+ms.readyState);ms.addEventListener('sourceopen',function(){send('media',label+' sourceopen readyState='+ms.readyState)});ms.addEventListener('sourceended',function(){send('media',label+' sourceended readyState='+ms.readyState)});ms.addEventListener('sourceclose',function(){send('media',label+' SOURCECLOSE readyState='+ms.readyState)});try{var _eos=ms.endOfStream.bind(ms);ms.endOfStream=function(r){send('media',label+' endOfStream reason='+r);return _eos(r)}}catch(e){}}function hookMSClass(cls,name){if(!cls)return;var orig=cls;window[name]=function(){var ms=new orig();hookMS(ms,name+'[ctor]');return ms};window[name].prototype=orig.prototype;window[name].isTypeSupported=orig.isTypeSupported?orig.isTypeSupported.bind(orig):undefined;send('info',name+' constructor hooked')}var _createObjURL=URL.createObjectURL.bind(URL);URL.createObjectURL=function(obj){var url=_createObjURL(obj);var type=obj&&obj.constructor?obj.constructor.name:'unknown';send('net','createObjectURL type='+type+' url='+String(url).slice(-40));if(obj&&(obj instanceof(window.ManagedMediaSource||function(){})||obj instanceof(window.MediaSource||function(){})))hookMS(obj,'MS[createObj]');return url};var _revokeObjURL=URL.revokeObjectURL.bind(URL);URL.revokeObjectURL=function(url){send('net','revokeObjectURL url='+String(url).slice(-40));_revokeObjURL(url)};var _srcObjDesc=Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype,'srcObject');if(_srcObjDesc&&_srcObjDesc.set){Object.defineProperty(HTMLMediaElement.prototype,'srcObject',{get:function(){return _srcObjDesc.get.call(this)},set:function(v){var type=v&&v.constructor?v.constructor.name:(v===null?'null':'unknown');send('media','srcObject SET type='+type+' on <'+this.tagName.toLowerCase()+'>');if(v&&(v instanceof(window.ManagedMediaSource||function(){})||v instanceof(window.MediaSource||function(){})))hookMS(v,'MS[srcObj]');return _srcObjDesc.set.call(this,v)},configurable:true})}else{send('info','srcObject descriptor NOT writable - trying instance override')}var _srcDesc=Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype,'src');if(_srcDesc&&_srcDesc.set){Object.defineProperty(HTMLMediaElement.prototype,'src',{get:function(){return _srcDesc.get.call(this)},set:function(v){send('media','src SET value='+String(v).slice(-60)+' on <'+this.tagName.toLowerCase()+'>');return _srcDesc.set.call(this,v)},configurable:true})}function getAudioInfo(el){var b=0,ahead=0;try{if(el.buffered&&el.buffered.length){b=el.buffered.end(el.buffered.length-1);ahead=b-el.currentTime}}catch(e){}var so=el.srcObject;var soStr=so?(so.constructor?so.constructor.name:'obj'):'null';return 't='+el.currentTime.toFixed(2)+'s ahead='+ahead.toFixed(2)+'s net='+el.networkState+' ready='+el.readyState+' paused='+el.paused+' srcObj='+soStr}function monitorMedia(){var els=document.querySelectorAll('audio,video');els.forEach(function(el,i){if(el.__monitored)return;el.__monitored=true;['stall','waiting','error','abort','playing','pause','ended','suspend','emptied','loadstart','loadedmetadata','canplay','canplaythrough'].forEach(function(ev){el.addEventListener(ev,function(){send('media',ev.toUpperCase()+' | '+getAudioInfo(el))})});send('media','Monitoring <'+el.tagName.toLowerCase()+'> #'+i+' | '+getAudioInfo(el));if(el.srcObject)hookMS(el.srcObject,'MS[existing]');send('media',' el.src='+String(el.src).slice(-60))});return els.length}var found=monitorMedia();if(!found){var ob=new MutationObserver(function(){if(monitorMedia()>0)ob.disconnect()});ob.observe(document.body,{childList:true,subtree:true})}hookMSClass(window.ManagedMediaSource,'ManagedMediaSource');hookMSClass(window.MediaSource,'MediaSource');var lastT=null,lastPollTime=0;setInterval(function(){var els=document.querySelectorAll('audio,video');if(!els.length)return;var el=els[0];var now=Date.now();if(lastT!==null){var elapsed=(now-lastPollTime)/1000;var drift=el.currentTime-(lastT+elapsed);if(Math.abs(drift)>0.8)send('media','DRIFT drift='+drift.toFixed(2)+'s | '+getAudioInfo(el));else send('media','POLL | '+getAudioInfo(el))}lastT=el.currentTime;lastPollTime=now},3000);var s=document.createElement('script');s.src='https://cdn.jsdelivr.net/npm/eruda';document.head.appendChild(s);s.onload=function(){eruda.init();send('info','Eruda OK')};})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment