fix: dev-console capture uses Blob with JSON content-type and fetch fallback

sendBeacon with a plain string sends Content-Type text/plain, which can
be silently blocked in Telegram WebView. Use a Blob with application/json
instead, and fall back to fetch with keepalive when sendBeacon is
unavailable or returns false.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
dj-oyu 2026-02-24 17:32:48 +09:00
parent 821392f346
commit 19298f1d6b

View file

@ -439,7 +439,11 @@ const devProxyScript = `<script data-dev-proxy>
_timer=null; _timer=null;
if(!_buf.length)return; if(!_buf.length)return;
var batch=_buf.splice(0,20); var batch=_buf.splice(0,20);
try{navigator.sendBeacon('/miniapp/dev/console',JSON.stringify(batch));}catch(e){} var payload=JSON.stringify(batch);
try{
if(navigator.sendBeacon&&navigator.sendBeacon('/miniapp/dev/console',new Blob([payload],{type:'application/json'})))return;
}catch(e){}
try{fetch('/miniapp/dev/console',{method:'POST',headers:{'Content-Type':'application/json'},body:payload,keepalive:true});}catch(e){}
} }
function _cap(level,args){ function _cap(level,args){
var msg=Array.prototype.map.call(args,function(a){ var msg=Array.prototype.map.call(args,function(a){