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 b5fda32416
commit 4d992a260e

View file

@ -439,7 +439,11 @@ const devProxyScript = `<script data-dev-proxy>
_timer=null;
if(!_buf.length)return;
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){
var msg=Array.prototype.map.call(args,function(a){