@@ -256,67 +256,203 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
256256 + "})()" , null );
257257 view .evaluateJavascript (
258258 "(function(){"
259- + "const BIN_REGEX=/ \\ .bin(?: \\ ?.*)?$/i ;"
260- + "console.log('[DEBUG] Network interceptor starting...') ;"
261- + "let requestCounter=0 ;"
259+ + "console.log('π Starting comprehensive network interception...') ;"
260+ + "let requestCounter = 0 ;"
261+ + "const BIN_REGEX = / \\ .bin(?: \\ ?.*)?$/i ;"
262262 + ""
263- + "// Intercept XMLHttpRequest"
264- + "const NativeXHR=XMLHttpRequest;"
265- + "window.XMLHttpRequest=function(){"
266- + " const xhr=new NativeXHR();"
267- + " const originalOpen=xhr.open;"
268- + " const originalSend=xhr.send;"
269- + " xhr.open=function(method,url,...args){"
270- + " this._url=url;"
271- + " this._isBin=BIN_REGEX.test(url);"
272- + " this._reqId=++requestCounter;"
273- + " console.log('[XHR]['+this._reqId+']',method,url,'is_bin:',this._isBin);"
274- + " return originalOpen.apply(this,[method,url,...args]);"
275- + " };"
276- + " xhr.send=function(...args){"
277- + " if(this._isBin){"
278- + " console.log('[XHR]['+this._reqId+'] BIN SENDING:',this._url);"
279- + " this.addEventListener('load',()=\u003e {"
280- + " console.log('[XHR]['+this._reqId+'] BIN LOADED:',this._url,'status:',this.status,'size:',this.response?this.response.byteLength||this.response.length:'unknown');"
281- + " });"
282- + " this.addEventListener('error',()=\u003e {"
283- + " console.error('[XHR]['+this._reqId+'] BIN ERROR:',this._url);"
284- + " });"
285- + " }"
286- + " return originalSend.apply(this,args);"
287- + " };"
288- + " return xhr;"
263+ + "// 1. XMLHttpRequest Interception"
264+ + "const OriginalXHR = XMLHttpRequest;"
265+ + "window.XMLHttpRequest = function() {"
266+ + " const xhr = new OriginalXHR();"
267+ + " const originalOpen = xhr.open;"
268+ + " const originalSend = xhr.send;"
269+ + " xhr.open = function(method, url, ...args) {"
270+ + " this._url = url;"
271+ + " this._method = method;"
272+ + " this._reqId = ++requestCounter;"
273+ + " console.log('π‘ [XHR][' + this._reqId + '] ' + method + ' ' + url);"
274+ + " if (BIN_REGEX.test(url)) console.log('π― [XHR][' + this._reqId + '] BIN FILE DETECTED: ' + url);"
275+ + " return originalOpen.apply(this, [method, url, ...args]);"
276+ + " };"
277+ + " xhr.send = function(...args) {"
278+ + " const self = this;"
279+ + " console.log('π€ [XHR][' + this._reqId + '] SENDING: ' + this._method + ' ' + this._url);"
280+ + " this.addEventListener('loadstart', () => console.log('β³ [XHR][' + self._reqId + '] LOADING STARTED'));"
281+ + " this.addEventListener('progress', (e) => console.log('π [XHR][' + self._reqId + '] PROGRESS: ' + e.loaded + '/' + e.total));"
282+ + " this.addEventListener('load', () => {"
283+ + " const size = self.response ? (self.response.byteLength || self.response.length || 'unknown') : 'none';"
284+ + " console.log('β
[XHR][' + self._reqId + '] LOADED: ' + self._url + ' | Status: ' + self.status + ' | Size: ' + size);"
285+ + " if (BIN_REGEX.test(self._url)) console.log('π― [XHR][' + self._reqId + '] BIN LOADED SUCCESS: ' + self._url);"
286+ + " });"
287+ + " this.addEventListener('error', () => {"
288+ + " console.error('β [XHR][' + self._reqId + '] ERROR: ' + self._url);"
289+ + " if (BIN_REGEX.test(self._url)) console.error('π¨ [XHR][' + self._reqId + '] BIN LOAD ERROR: ' + self._url);"
290+ + " });"
291+ + " this.addEventListener('timeout', () => console.error('β° [XHR][' + self._reqId + '] TIMEOUT: ' + self._url));"
292+ + " this.addEventListener('abort', () => console.warn('π [XHR][' + self._reqId + '] ABORTED: ' + self._url));"
293+ + " return originalSend.apply(this, args);"
294+ + " };"
295+ + " return xhr;"
289296 + "};"
290297 + ""
291- + "// Intercept fetch API"
292- + "const NativeFetch=window.fetch;"
293- + "window.fetch=function(input,init){"
294- + " const url=typeof input==='string'?input:input.url;"
295- + " const isBin=BIN_REGEX.test(url);"
296- + " const reqId=++requestCounter;"
297- + " console.log('[FETCH]['+reqId+']',url,'is_bin:',isBin);"
298- + " if(isBin){"
299- + " console.log('[FETCH]['+reqId+'] BIN FETCH:',url);"
300- + " }"
301- + " return NativeFetch.apply(this,arguments).then(response=\u003e {"
302- + " if(isBin){"
303- + " console.log('[FETCH]['+reqId+'] BIN RESPONSE:',url,'status:',response.status,'ok:',response.ok);"
304- + " }"
305- + " return response;"
306- + " }).catch(err=\u003e {"
307- + " if(isBin){"
308- + " console.error('[FETCH]['+reqId+'] BIN ERROR:',url,err);"
298+ + "// 2. Fetch API Interception"
299+ + "const OriginalFetch = window.fetch;"
300+ + "window.fetch = function(input, init) {"
301+ + " const url = typeof input === 'string' ? input : input.url;"
302+ + " const reqId = ++requestCounter;"
303+ + " const method = init?.method || 'GET';"
304+ + " console.log('π [FETCH][' + reqId + '] ' + method + ' ' + url);"
305+ + " if (BIN_REGEX.test(url)) console.log('π― [FETCH][' + reqId + '] BIN FILE DETECTED: ' + url);"
306+ + " return OriginalFetch.apply(this, arguments)"
307+ + " .then(response => {"
308+ + " console.log('β
[FETCH][' + reqId + '] RESPONSE: ' + url + ' | Status: ' + response.status + ' | OK: ' + response.ok);"
309+ + " if (BIN_REGEX.test(url)) console.log('π― [FETCH][' + reqId + '] BIN RESPONSE SUCCESS: ' + url);"
310+ + " return response;"
311+ + " })"
312+ + " .catch(error => {"
313+ + " console.error('β [FETCH][' + reqId + '] ERROR: ' + url + ' | ' + error.message);"
314+ + " if (BIN_REGEX.test(url)) console.error('π¨ [FETCH][' + reqId + '] BIN FETCH ERROR: ' + url);"
315+ + " throw error;"
316+ + " });"
317+ + "};"
318+ + ""
319+ + "// 3. WebSocket Interception"
320+ + "const OriginalWebSocket = WebSocket;"
321+ + "window.WebSocket = function(url, protocols) {"
322+ + " const wsId = ++requestCounter;"
323+ + " console.log('π [WS][' + wsId + '] CONNECTING: ' + url);"
324+ + " const ws = new OriginalWebSocket(url, protocols);"
325+ + " ws.addEventListener('open', () => console.log('β
[WS][' + wsId + '] CONNECTED: ' + url));"
326+ + " ws.addEventListener('message', (e) => console.log('π¨ [WS][' + wsId + '] MESSAGE: ' + (typeof e.data === 'string' ? e.data.substring(0, 100) : '[Binary]')));"
327+ + " ws.addEventListener('error', () => console.error('β [WS][' + wsId + '] ERROR: ' + url));"
328+ + " ws.addEventListener('close', () => console.log('π [WS][' + wsId + '] CLOSED: ' + url));"
329+ + " return ws;"
330+ + "};"
331+ + ""
332+ + "// 4. Service Worker Registration"
333+ + "if ('serviceWorker' in navigator) {"
334+ + " const originalRegister = navigator.serviceWorker.register;"
335+ + " navigator.serviceWorker.register = function(scriptURL, options) {"
336+ + " const swId = ++requestCounter;"
337+ + " console.log('βοΈ [SW][' + swId + '] REGISTERING: ' + scriptURL);"
338+ + " return originalRegister.apply(this, arguments)"
339+ + " .then(registration => {"
340+ + " console.log('β
[SW][' + swId + '] REGISTERED: ' + scriptURL);"
341+ + " return registration;"
342+ + " })"
343+ + " .catch(error => {"
344+ + " console.error('β [SW][' + swId + '] REGISTRATION FAILED: ' + scriptURL + ' | ' + error.message);"
345+ + " throw error;"
346+ + " });"
347+ + " };"
348+ + "}"
349+ + ""
350+ + "// 5. Web Worker Creation"
351+ + "const OriginalWorker = Worker;"
352+ + "window.Worker = function(scriptURL, options) {"
353+ + " const workerId = ++requestCounter;"
354+ + " console.log('π· [WORKER][' + workerId + '] CREATING: ' + scriptURL);"
355+ + " const worker = new OriginalWorker(scriptURL, options);"
356+ + " worker.addEventListener('message', (e) => console.log('π¨ [WORKER][' + workerId + '] MESSAGE: ' + JSON.stringify(e.data).substring(0, 100)));"
357+ + " worker.addEventListener('error', (e) => console.error('β [WORKER][' + workerId + '] ERROR: ' + e.message));"
358+ + " return worker;"
359+ + "};"
360+ + ""
361+ + "// 6. EventSource (Server-Sent Events)"
362+ + "const OriginalEventSource = EventSource;"
363+ + "window.EventSource = function(url, eventSourceInitDict) {"
364+ + " const esId = ++requestCounter;"
365+ + " console.log('π‘ [SSE][' + esId + '] CONNECTING: ' + url);"
366+ + " const es = new OriginalEventSource(url, eventSourceInitDict);"
367+ + " es.addEventListener('open', () => console.log('β
[SSE][' + esId + '] CONNECTED: ' + url));"
368+ + " es.addEventListener('message', (e) => console.log('π¨ [SSE][' + esId + '] MESSAGE: ' + e.data.substring(0, 100)));"
369+ + " es.addEventListener('error', () => console.error('β [SSE][' + esId + '] ERROR: ' + url));"
370+ + " return es;"
371+ + "};"
372+ + ""
373+ + "// 7. DOM Element Network Activity"
374+ + "function interceptElementLoading(tagName, srcAttr) {"
375+ + " const OriginalCreateElement = document.createElement;"
376+ + " document.createElement = function(tag) {"
377+ + " const element = OriginalCreateElement.call(this, tag);"
378+ + " if (tag.toLowerCase() === tagName.toLowerCase()) {"
379+ + " const originalSetAttribute = element.setAttribute;"
380+ + " element.setAttribute = function(name, value) {"
381+ + " if (name === srcAttr) {"
382+ + " const elemId = ++requestCounter;"
383+ + " console.log('π·οΈ [' + tagName.toUpperCase() + '][' + elemId + '] LOADING: ' + value);"
384+ + " if (BIN_REGEX.test(value)) console.log('π― [' + tagName.toUpperCase() + '][' + elemId + '] BIN DETECTED: ' + value);"
385+ + " element.addEventListener('load', () => console.log('β
[' + tagName.toUpperCase() + '][' + elemId + '] LOADED: ' + value));"
386+ + " element.addEventListener('error', () => console.error('β [' + tagName.toUpperCase() + '][' + elemId + '] ERROR: ' + value));"
387+ + " }"
388+ + " return originalSetAttribute.call(this, name, value);"
389+ + " };"
390+ + " }"
391+ + " return element;"
392+ + " };"
393+ + "}"
394+ + "interceptElementLoading('img', 'src');"
395+ + "interceptElementLoading('script', 'src');"
396+ + "interceptElementLoading('link', 'href');"
397+ + ""
398+ + "// 8. WebGL Context Creation"
399+ + "const OriginalGetContext = HTMLCanvasElement.prototype.getContext;"
400+ + "HTMLCanvasElement.prototype.getContext = function(contextType, ...args) {"
401+ + " const context = OriginalGetContext.apply(this, arguments);"
402+ + " if (contextType === 'webgl' || contextType === 'webgl2') {"
403+ + " const glId = ++requestCounter;"
404+ + " console.log('π¨ [WebGL][' + glId + '] CONTEXT CREATED: ' + contextType);"
405+ + " if (context && context.shaderSource) {"
406+ + " const originalShaderSource = context.shaderSource;"
407+ + " context.shaderSource = function(shader, source) {"
408+ + " console.log('π¨ [WebGL][' + glId + '] SHADER SOURCE SET (length: ' + source.length + ')');"
409+ + " return originalShaderSource.apply(this, arguments);"
410+ + " };"
411+ + " }"
309412 + " }"
310- + " throw err;"
311- + " });"
413+ + " return context;"
312414 + "};"
313415 + ""
314- + "// Log all network activity for debugging"
315- + "setInterval(()=\u003e {"
316- + " console.log('[DEBUG] Network monitor active - total requests:',requestCounter);"
317- + "},10000);"
416+ + "// 9. Blob URL Creation"
417+ + "const OriginalCreateObjectURL = URL.createObjectURL;"
418+ + "URL.createObjectURL = function(object) {"
419+ + " const blobId = ++requestCounter;"
420+ + " const url = OriginalCreateObjectURL.apply(this, arguments);"
421+ + " console.log('π§ [BLOB][' + blobId + '] URL CREATED: ' + url + ' | Type: ' + (object.type || 'unknown') + ' | Size: ' + (object.size || 'unknown'));"
422+ + " return url;"
423+ + "};"
424+ + ""
425+ + "// 10. MutationObserver for Dynamic Elements"
426+ + "const observer = new MutationObserver(function(mutations) {"
427+ + " mutations.forEach(function(mutation) {"
428+ + " mutation.addedNodes.forEach(function(node) {"
429+ + " if (node.nodeType === Node.ELEMENT_NODE) {"
430+ + " const tagName = node.tagName.toLowerCase();"
431+ + " if (tagName === 'img' && node.src) {"
432+ + " const imgId = ++requestCounter;"
433+ + " console.log('πΌοΈ [IMG_DYNAMIC][' + imgId + '] ADDED: ' + node.src);"
434+ + " if (BIN_REGEX.test(node.src)) console.log('π― [IMG_DYNAMIC][' + imgId + '] BIN DETECTED: ' + node.src);"
435+ + " } else if (tagName === 'script' && node.src) {"
436+ + " const scriptId = ++requestCounter;"
437+ + " console.log('π [SCRIPT_DYNAMIC][' + scriptId + '] ADDED: ' + node.src);"
438+ + " if (BIN_REGEX.test(node.src)) console.log('π― [SCRIPT_DYNAMIC][' + scriptId + '] BIN DETECTED: ' + node.src);"
439+ + " } else if (tagName === 'link' && node.href) {"
440+ + " const linkId = ++requestCounter;"
441+ + " console.log('π [LINK_DYNAMIC][' + linkId + '] ADDED: ' + node.href);"
442+ + " if (BIN_REGEX.test(node.href)) console.log('π― [LINK_DYNAMIC][' + linkId + '] BIN DETECTED: ' + node.href);"
443+ + " }"
444+ + " }"
445+ + " });"
446+ + " });"
447+ + "});"
448+ + "observer.observe(document, { childList: true, subtree: true });"
449+ + ""
450+ + "// 11. Network Activity Monitor"
451+ + "setInterval(() => {"
452+ + " console.log('π [MONITOR] Total network operations tracked: ' + requestCounter);"
453+ + "}, 15000);"
318454 + ""
319- + "console.log('[DEBUG] Network interceptors installed ( XHR + fetch) ');"
455+ + "console.log('π Comprehensive network interception active! Monitoring XHR, Fetch, WebSocket, Workers, SSE, DOM elements, WebGL, and Blobs. ');"
320456 + "})()" , null );
321457 }
322458 });
0 commit comments