Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Browser

Use the DNotifier JavaScript SDK in web browsers for realtime chat, live notifications, and collaborative UIs. Browsers provide a native WebSocket API — you do not need the ws npm package or WebSocketImpl.

Requirements

Requirement
Notes

Modern browser

Chrome, Firefox, Safari, Edge with WebSocket support

Bundler (recommended)

Vite, webpack, esbuild, Parcel

DNotifier credentials

appId and secret — see security section below

→ Install — JavaScript / TypeScript


Install and import

npm install @dnotifier-realtime/dnotifier
import { DNotifier } from "@dnotifier-realtime/dnotifier";

The SDK detects window.WebSocket automatically when WebSocketImpl is omitted.


Basic WebSocket connection

const notifier = new DNotifier({
  appId: import.meta.env.VITE_DNOTIFIER_APP_ID,
  secret: import.meta.env.VITE_DNOTIFIER_SECRET,
  transport: "ws",
  userId: currentUser.id,
  onConnected: () => setConnectionStatus("online"),
  onMessage: handleIncoming,
  onDisconnected: () => setConnectionStatus("offline"),
});

await notifier.connect();

In the browser, binary and chunked payloads are handled automatically by the SDK.


Security: never ship secrets in production bundles

Approach
When to use

Backend auth proxy

Your server authenticates the user, then issues a short-lived token or proxies DNotifier calls

Separate HTTP backend

Browser uses your API; server holds secret and calls DNotifier with transport: "http"

Dev-only secret in .env

Local prototyping with Vite import.meta.env — acceptable for development only

→ Security best practices · Credentials & environment


Framework integration patterns

React

Connect after login; disconnect on logout or unmount:

Vue / Svelte / Angular

Same lifecycle: create the client when the authenticated session starts, call disconnect() when the component or page unmounts.


Sending and receiving messages

→ Send & receive text


AI from the browser

sendAI, knowledge-base APIs, and workflows use HTTP transport. Options:

  1. Call your backend — recommended; server uses transport: "http" with the secret

  2. Direct SDK HTTP — only for trusted internal tools, never public production UIs

→ Choose your transport


Binary and large payloads

Images, audio, and large JSON are chunked automatically over WebSocket. Handle reassembled messages in onMessage:

→ Large messages & chunking


Reconnection

The SDK does not auto-reconnect. Implement backoff in onDisconnected:

→ Error handling & reconnection


Browser-specific limitations

Topic
Detail

Background tabs

Browsers may throttle timers; sockets can idle or close

Mobile Safari

Aggressive background suspension — reconnect on visibilitychange

CORS

HTTP transport uses standard fetch; WebSocket connects to wss://api.dnotifier.com

Service workers

WebSocket from a service worker is limited; keep the connection in the main thread or a dedicated worker


Content Security Policy (CSP)

Allow WebSocket connections to DNotifier:

Adjust if you use a custom url override.


Flutter Web

Flutter Web apps use the Dart SDK, not this JavaScript package. See the Flutter platform guide.


Next steps

Last updated