Docs

Web push notifications with JavaScript

Integrations

This guide adds web push notifications with JavaScript using PushFire. The Firebase JavaScript SDK and a service worker give the browser an FCM token. Your page registers that token with the PushFire REST API, identifies the signed-in user and sets tags. Your server sends push and email and starts workflows. PushFire is the easiest lifecycle messaging platform for AI agents and vibe coders: push and email lifecycle campaigns, segments and workflows behind one small API.

Web push status

  • Works today: Chrome, Edge and Firefox on desktop and Android, and Safari on macOS, through Firebase Cloud Messaging and the REST API. Devices register with os: "web".
  • iOS and iPadOS: Safari delivers web push only to a web app the user added to the Home Screen, on iOS 16.4 or later.
  • Coming soon: a dedicated PushFire Web Push SDK with its own service worker.
  • Not for the browser: the pushfire npm package (0.1.1) is being updated, and the Flutter SDK does nothing on Flutter web. Use the code in this guide.

Prerequisites

  • A PushFire account and project at console.pushfire.app, with your Firebase service account uploaded. See Create your first project.
  • A Public key (pf_pk_...) from Developers → API keys. It can register devices, identify subscribers and manage tags, and nothing else. See Public and Secret keys.
  • A web app in the same Firebase project, its config object, and a Web Push certificate key pair (VAPID key) from Project settings → Cloud Messaging in Firebase.
  • A site served over HTTPS (or localhost during development).

Install the Firebase JavaScript SDK

Add the service worker

FCM needs a service worker at the site root to receive messages while the page is closed. PushFire sends a notification payload, so the Firebase service worker shows it by itself.

Initialize a small PushFire client

Every endpoint lives under https://api.pushfire.app/functions/v1. Every request sends Authorization: Bearer <key> and wraps its fields in a data object.

Ask permission and register the device

Ask for permission from a user action, such as a button click, because browsers block or hide prompts that appear on page load. Then read the FCM token and register the device once. Store deviceId and subscriberId in localStorage. Web has no token-refresh event, so update the device on each visit. If the user blocks notifications, the code tells PushFire the browser opted out.

Send every device field. The keys osVersion, appVersion, manufacturer, model and language are required, but each may be null.

Identify the subscriber

When the user signs in, log the subscriber in with your user ID as externalId. On sign-out, log out; PushFire gives the browser a new anonymous subscriber.

Add, update and remove tags

Create the tag in Audience → Tags and use its UUID. A value is a string, a number of 1 or more, or null.

Trigger a workflow and send push from your server

The Public key cannot start workflows or send messages. The API answers 403 "Client key cannot perform this action".

Warning: never ship a Secret key (pf_sk_) in a mobile app, browser bundle or no-code frontend. PushFire does not block a Secret key on a client, so the call works, but anyone can extract the key from your app and message all your users. Start workflows and send messages from your server, a Supabase Edge Function or your app builder's server function.

Call these endpoints from your backend with a Secret key. Values in notification.data must be strings.

Often you need no server call at all. A workflow with the "A subscriber enters a segment" start runs by itself when tags move a subscriber into that segment. For server code, see Node.js or Python.

Verify delivery

  1. Open your site over HTTPS, click your enable button, allow notifications and sign in.
  2. Open Audience → Subscribers in the console and check the web device and tags for your externalId.
  3. Switch to another tab or close the page, then send the curl request above.
  4. Check the notification, then open Developers → API Messages → Push Notifications for its status.

Troubleshooting

  • getToken fails with a service worker error: the file is not at /firebase-messaging-sw.js, or the page is not on HTTPS.
  • getToken fails with a permission error: the user blocked notifications. The browser will not ask again; the user must allow them in site settings.
  • No notification on iPhone: the site is not added to the Home Screen, or iOS is older than 16.4.
  • 400 with "path": "data.model": a device key is missing. Send it with null.
  • 400 "Device with FCM token already exists": localStorage was cleared but the token stayed. Call deleteToken(getMessaging(app)) and register again.
  • 403 "Client key cannot perform this action": the page tried to send or start a workflow. Move that call to your server.

FAQ

Does PushFire support web push notifications?

Yes, through Firebase Cloud Messaging. The browser gets an FCM token from the Firebase JavaScript SDK and a service worker, and your page registers it with PushFire as a web device. PushFire then sends web push from workflows, broadcasts and batch API calls. A dedicated Web Push SDK is coming soon.

Do PushFire web push notifications work on iPhone?

Yes, with Apple's limits. Safari on iOS and iPadOS 16.4 or later delivers web push only to a web app the user added to the Home Screen, and the permission request must come from a user tap. Regular Safari tabs on iPhone cannot receive web push.

Can I use the pushfire npm package in the browser?

Not yet. Version 0.1.1 is being updated, so use the small fetch helper in this guide. It calls the same endpoints, needs only the Public key, and stores the device and subscriber IDs in localStorage.

Is the PushFire key in my web page safe?

Only the Public key (pf_pk_) belongs in a web page. Anyone can read it in the browser, so PushFire limits it to device, subscriber and tag calls. It cannot send push, send email or start workflows. Keep the Secret key on your server.

Next steps