Skip to main content

Push notifications: web app guide

Guide for the web team: how a browser app (customer dashboard or web console) tells the user about new alerts.

:::note Status (2026-11-11) Browser (Web Push) notifications are built on the backend, not deployed yet. The web app cse-solar-app is registered in the Firebase project. A browser token can be registered over the WebSocket (register_push_token, "platform": "web", enabled 2026-11-11) or with the HTTP server (cse-http-be ADR 0022, End Users only). See Browser push. :::

What to build now​

While the tab is open, the WebSocket already delivers every alert in real time, so the web app doesn't need system notifications to be useful:

PieceMessagesNeeds a realtime ticket
Live toast when an alert is raisedalerts_changed (after subscribe_alerts), or alert_updated on a console connectionNo for alerts_changed on dev; yes for alert_updated
Bell with unread countalerts_summary / alerts_changed unreadCount, mark_alerts_readNo on dev
Notification inbox (device-alert notifications for the user)get_notification_deliveries, mark_notifications_readYes

Connecting, authenticating and reconnecting are covered in Web client and Authentication.

1. Live toasts​

Subscribe once per connection, and again after every reconnect:

{"type": "subscribe_alerts", "userId": "<user id>", "plantId": "all"}

The server answers with alerts_summary, then pushes alerts_changed whenever an alert in that scope is raised, resolved or updated. One push covers one device scan and can carry several alerts. Full shapes are in Device alerts.

Show a toast for raised events only, one toast per message (not per alert), matching how the phone groups them:

type AlertEvent = { op: 'raised' | 'resolved' | 'updated'; alert: Alert };

function onAlertsChanged(msg: { events: AlertEvent[]; unreadCount: number }) {
setUnreadCount(msg.unreadCount);

const raised = msg.events.filter(e => e.op === 'raised').map(e => e.alert);
if (raised.length === 0) return;

const rank = { info: 1, warning: 2, critical: 3 } as const;
const top = raised.reduce((a, b) => (rank[b.severity] > rank[a.severity] ? b : a));
const device = top.inverterSn ? `Inverter ${top.inverterSn}` : `Logger ${top.loggerId}`;

showToast({
severity: top.severity,
title: raised.length === 1
? top.title
: `${raised.length} new alerts`,
body: raised.length === 1
? `${device} — ${top.message}`
: `${device} — ${raised.slice(0, 3).map(a => a.title).join(', ')}`,
// One alert: open it. Several: open the device's alert list.
href: raised.length === 1 ? `/alerts/${top.id}` : `/devices/${top.deviceKey}/alerts`,
// Critical stays until dismissed; others auto-hide.
sticky: top.severity === 'critical',
});
}

On the web console (a connection authenticated with a ticket), alerts arrive as alert_updated with op: "raised", one alert per message. See alert_updated push. Batch toasts that arrive within a second or two of each other for the same deviceKey, so a grid failure doesn't produce five toasts.

Don't use the browser Notification API for these toasts while the tab is in the foreground; an in-page toast is enough and needs no permission.

2. Bell and unread count​

  • Initial count: alerts_summary.unreadCount (the reply to subscribe_alerts).
  • Live updates: every alerts_changed carries the new unreadCount.
  • Opening the bell or an alert: mark_alerts_read / mark_all_alerts_read.

See Read state. Optionally put the count in the tab title ((3) Crown Solar), which users notice when the tab is in the background.

3. Notification inbox (optional)​

The backend records each device-alert notification for the device's owner, for 90 days, with its own unread count. The entry is written before the push is sent, and also when no push goes out (no registered token, push turned off, quiet hours). If the design has a "Notifications" list separate from alerts, read it with get_notification_deliveries and clear it with mark_notifications_read. Both need a connection authenticated with a realtime ticket, and are documented in the web console's Notification inbox.

const page = await rpc('get_notification_deliveries', { unreadOnly: false, limit: 50 });
render(page.items); // newest first; page.cursor for more
setInboxBadge(page.unreadCount); // page.unreadCapped: show "999+"

// When the user has seen the list:
const newest = page.items[0]?.sentAt;
if (newest) await rpc('mark_notifications_read', { all: true, upTo: newest });

Pass the newest sentAt you displayed as upTo, so entries that arrived after you rendered stay unread.

This inbox only holds alerts on devices the user owns (raises, and clears of notify_on_resolve codes). Work-order and report notifications are in the HTTP server's own inbox (GET /v1/me/notifications). The alert list is the complete alert record.

Browser push​

The browser gets a system notification even when no console tab is open, through Firebase Cloud Messaging (dev project cse-datalogger) and the browser's Web Push service. Alert pushes go to the owner of the device that raised the alert, so a browser only gets alerts for devices its signed-in user owns.

Web side:

  1. Firebase web config (firebaseConfig, public) with the firebase package's messaging module, and the VAPID public key from Firebase → Cloud Messaging → Web Push certificates (public).
  2. Service worker firebase-messaging-sw.js at the site root over HTTPS. Every message has a notification block, so the Firebase SDK shows it while no tab is focused; with a tab open, onMessage receives it and the console shows a toast instead.
  3. Permission on a user action, never on page load. Detect Notification.permission === 'denied' and explain how to re-enable it in the browser's site settings.
  4. Register the token from getToken(messaging, { vapidKey, serviceWorkerRegistration }), in one of two ways (a token registered both ways still gets one push):
    • over the WebSocket, after every (re)connect and after auth_result when using a ticket:

      {"type": "register_push_token", "userId": "<user id>",
      "token": "<getToken() result>", "platform": "web"}

      answered by push_token_result. Send unregister_push_token on sign-out. Rules and errors are in Push notifications. This path gets alert pushes only;

    • with the HTTP server: POST /v1/me/push-tokens with platform: "WEB". Re-posting a token already registered does not count toward the 20-per-day limit. This path also gets the work-order and report pushes below, and only End Users' tokens are passed on (a person with any staff membership gets 201 but nothing is sent).

  5. Click opens webpush.fcm_options.link, a console path. The same path is in data.link, for a service worker that handles clicks itself.

What arrives (full tables in Push notifications):

Pushtitle / bodydata.typedata.tag = notification tagLink
Alert raised on a device you ownCritical: Grid over-voltage / Inverter SN123 — …alertalert-<alertId>/alerts?alert=<alertId>
Alert cleared (notify_on_resolve codes only)Resolved: Logger Back Online / Inverter SN123alert_resolvedalert-<alertId> (replaces the raise)/alerts?alert=<alertId>
Work order (HTTP inbox item; HTTP-registered tokens only)from the HTTP serverfrom the HTTP serverwo-<workOrderId>/service?order=<workOrderId>
Report ready (HTTP inbox item; HTTP-registered tokens only)from the HTTP serverfrom the HTTP serverreport-<reportId>/reports

Every message also has webpush.notification.icon /brand/logo-mark.png. The user's push preference and personal quiet hours (set in the HTTP server) apply to all of them, except that critical alerts always go through. A token Firebase reports dead (browser data cleared, permission revoked) is dropped (on both servers for an HTTP-registered token); the next getToken on that browser registers a new one.

Things to plan for:

  • Safari supports Web Push from macOS 13 and iOS 16.4, on iOS only for a site added to the Home Screen.
  • Each browser profile is one token.

Testing the in-app pieces​

  1. Open the web app signed in as a user who owns the bench inverter.
  2. Unplug the logger for 6 minutes ("Logger Offline"), or cause a real inverter fault (battery BMS cable or grid input).
  3. A toast appears and the bell count goes up. Plug the logger back in and leave it connected: about 10-11 minutes later the alert shows as resolved in the list (an offline alert resolves only once the logger has stayed connected for 10 minutes). With browser push set up and the tab closed, a "Resolved: Logger Back Online" notification replaces the "Logger Offline" one.
  4. Kill the network for a minute, reconnect, and check subscribe_alerts is re-sent and toasts still arrive.