SOURCE

console 命令行工具 X clear

                    
>
console
sendEvent.addEventListener('click',function(){
    navigator.sendBeacon('https://httpbin.org/post','reqId='+Math.random())
})

window.onbeforeunload = function(){
    navigator.sendBeacon('https://httpbin.org/post','reqId2='+Math.random())
}

window.onload = ()=>{
    navigator.sendBeacon('https://httpbin.org/post','reqId2='+Math.random())
}
<button id="sendEvent">发送事件</button>