Files
elysium/apps/web/src/utils/notification.ts
T
hikari a36c8e72a5
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m3s
CI / Lint, Build & Test (push) Successful in 1m8s
feat: error handling, logging, analytics, OG tags, and sticky sidebar (#44)
## Summary

- Add comprehensive try/catch error handling across all API routes, middleware, and the Hono global error handler, piping every unhandled error to the `@nhcarrigan/logger` service to prevent silent crashes and unhandled Promise rejections
- Add a `logError` utility on the frontend that forwards errors through the overridden `console.error` to the backend telemetry endpoint; apply it to every silent `catch {}` block in the game context, sound, notification, and clipboard utilities, and wrap the React tree in an `ErrorBoundary`
- Add Plausible analytics, Open Graph + Twitter Card meta tags, Tree-Nation widget, and Google Ads to `index.html`
- Make the game sidebar sticky with a `--resource-bar-height` CSS custom property offset so it stays viewport-height without overlapping the resource bar; reset sticky behaviour in the mobile responsive override

## Test plan

- [ ] Lint passes: `pnpm lint`
- [ ] Build passes: `pnpm build`
- [ ] Verify errors thrown in API routes appear in the logger service rather than crashing the process
- [ ] Verify frontend errors appear in the `/api/fe/error` backend log
- [ ] Verify Open Graph tags render correctly when sharing the URL
- [ ] Verify Plausible analytics fires on page load
- [ ] Verify Tree-Nation badge renders in the sidebar
- [ ] Verify sidebar stays fixed while the main content scrolls on desktop
- [ ] Verify mobile layout is unaffected

 This issue was created with help from Hikari~ 🌸

Reviewed-on: #44
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-09 19:54:42 -07:00

49 lines
1.4 KiB
TypeScript

/**
* @file Browser notification utilities.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { logError } from "./logError.js";
/**
* Requests browser notification permission from the user.
* @returns Whether permission was granted.
*/
const requestNotificationPermission = async(): Promise<boolean> => {
if (typeof Notification === "undefined") {
return false;
}
if (Notification.permission === "granted") {
return true;
}
if (Notification.permission === "denied") {
return false;
}
const permission = await Notification.requestPermission();
return permission === "granted";
};
/**
* Sends a browser notification if permission has been granted.
* @param title - The notification title text.
* @param body - The notification message displayed below the title.
*/
const sendNotification = (title: string, body: string): void => {
if (
typeof Notification === "undefined"
|| Notification.permission !== "granted"
) {
return;
}
try {
// eslint-disable-next-line no-new -- Notification constructor has side effects
new Notification(title, { body: body, icon: "/favicon.ico" });
} catch (error_: unknown) {
logError("send_notification", error_);
// Silently ignore — notifications may fail silently
}
};
export { requestNotificationPermission, sendNotification };