| 104 | } |
| 105 | |
| 106 | function send(url: string, payload: string): void { |
| 107 | // Prefer fetch with keepalive (survives page navigation). sendBeacon is a |
| 108 | // fallback for older runtimes where fetch isn't available. |
| 109 | try { |
| 110 | void fetch(url, { |
| 111 | method: "POST", |
| 112 | headers: { "Content-Type": "application/json" }, |
| 113 | body: payload, |
| 114 | keepalive: true, |
| 115 | }).catch(() => { |
| 116 | /* silent */ |
| 117 | }); |
| 118 | return; |
| 119 | } catch { |
| 120 | /* fall through */ |
| 121 | } |
| 122 | try { |
| 123 | navigator.sendBeacon(url, new Blob([payload], { type: "application/json" })); |
| 124 | } catch { |
| 125 | /* silent */ |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | function showNoticeOnce(): void { |
| 130 | if (hasShownNotice()) return; |