if (navigator.sendBeacon) {
    let data = new FormData();
    data.append('fingerprint', '<?php echo $agent->fingerprint;?>');
    data.append('browser', '<?php echo $browser;?>');
    data.append('type', '<?php echo $custom_err;?>');
    data.append('code', '<?php echo $resp_code;?>');
    data.append('ver', '<?php echo BITFIRE_VER;?>');
    navigator.sendBeacon("https://bitfire.co/ray.php", data);
}


document.getElementById("review").addEventListener("click", function (event) {
    const e=window.event;
    const uuid = e.currentTarget.getAttribute("data-reference");
    let data={"uuid":uuid,"x":e.clientX,"y":e.clientY};
    console.log(e, uuid, data);
    let name = prompt("short message for the administrator to review your request", "");
    data["name"] = name;
    if (navigator.sendBeacon) {
        let data2 = new FormData();
        data2.append('fingerprint', '<?php echo $fingerprint; ?>');
        data2.append('type', 'verify');
        data2.append('name', data["name"]);
        data2.append('uuid', data["uuid"]);
        data2.append('x', data["x"]);
        data2.append('y', data["y"]);
        navigator.sendBeacon("https://bitfire.co/ray.php", data2);
    }

    if (name != null) {
        const response = fetch("/?BITFIRE_API=review", {
        method:'POST',mode:'no-cors',cache:'no-cache',credentials:'omit',headers:{'Content-Type': 'application/json'},redirect:'follow',referrerPolicy:'unsafe-url',body:JSON.stringify(data)
        }).then((response) => response.json()).then((data) => alert(data.note));
    }
});
