|
| 1 | +import * as Sentry from "@sentry/solid"; |
| 2 | + |
| 3 | +const showCrashPopup = (message: string) => { |
| 4 | + const existingDiv = document.getElementById("crash-reporter-popup"); |
| 5 | + const div = existingDiv || document.createElement("div"); |
| 6 | + div.id = "crash-reporter-popup"; |
| 7 | + div.style.cssText = ` |
| 8 | + position: fixed; |
| 9 | + top: 20px; |
| 10 | + left: 50%; |
| 11 | + transform: translateX(-50%); |
| 12 | + background: black; |
| 13 | + color: #fab1a0; |
| 14 | + padding: 20px; |
| 15 | + border-radius: 12px; |
| 16 | + z-index: 999999; |
| 17 | + box-shadow: 0 10px 30px rgba(0,0,0,0.5); |
| 18 | + max-width: 400px; |
| 19 | + width: 90%; |
| 20 | + border-left: 5px solid #ff7675; |
| 21 | + border: solid 1px rgba(255,255,255,0.4); |
| 22 | + `; |
| 23 | + |
| 24 | + div.innerHTML = ` |
| 25 | + <div style="font-weight: bold; font-size: 18px; margin-bottom: 10px; color: #ff7675;"> |
| 26 | + ⚠️ Nerimity Has Crashed |
| 27 | + </div> |
| 28 | + <div style="font-size: 14px; color: #dfe6e9; line-height: 1.4; margin-bottom: 20px; word-break: break-word;"> |
| 29 | + ${message} |
| 30 | + <div style="margin-top: 10px;opacity: 0.8">See the console for more details. <code style="color: #ff7675; font-size: 12px">(CTRL + SHIFT + I)</code></div> |
| 31 | + </div> |
| 32 | + <div style="display: flex; gap: 10px;"> |
| 33 | + <button id="crash-reload" style="flex: 1; background: var(--alert-color); color: white; border: none; padding: 10px; border-radius: 6px; cursor: pointer; font-weight: bold;"> |
| 34 | + Reload Page |
| 35 | + </button> |
| 36 | + <button id="crash-close" style="flex: 1; background: #1a1a1a; color: white; border: none; padding: 10px; border-radius: 6px; cursor: pointer;"> |
| 37 | + Dismiss |
| 38 | + </button> |
| 39 | + </div> |
| 40 | + `; |
| 41 | + |
| 42 | + if (!existingDiv) { |
| 43 | + document.body.appendChild(div); |
| 44 | + } |
| 45 | + document.getElementById("crash-reload")!.onclick = () => { |
| 46 | + window.location.reload(); |
| 47 | + }; |
| 48 | + |
| 49 | + document.getElementById("crash-close")!.onclick = () => { |
| 50 | + div.remove(); |
| 51 | + }; |
| 52 | +}; |
| 53 | + |
| 54 | +Sentry.init({ |
| 55 | + dsn: "http://0@0.ingest.sentry.io/0", |
| 56 | + async beforeSend(event) { |
| 57 | + const exception = event.exception?.values?.[0]; |
| 58 | + const msg = exception?.value || "Unknown Error"; |
| 59 | + const frame = exception?.stacktrace?.frames?.slice().reverse()[0]; |
| 60 | + |
| 61 | + if (frame) { |
| 62 | + try { |
| 63 | + const { TraceMap, originalPositionFor } = await import( |
| 64 | + "@jridgewell/trace-mapping" |
| 65 | + ); |
| 66 | + const res = await fetch(`${frame.filename}.map`); |
| 67 | + const tracer = new TraceMap(await res.json()); |
| 68 | + const orig = originalPositionFor(tracer, { |
| 69 | + line: frame.lineno!, |
| 70 | + column: frame.colno!, |
| 71 | + }); |
| 72 | + |
| 73 | + if (orig.source) { |
| 74 | + showCrashPopup( |
| 75 | + `${msg}<br/>${orig.source}:${orig.line}:${orig.column}` |
| 76 | + ); |
| 77 | + return null; |
| 78 | + } |
| 79 | + } catch { |
| 80 | + // |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + showCrashPopup(`${msg}`); |
| 85 | + return null; |
| 86 | + }, |
| 87 | +}); |
0 commit comments