Push & Web Notifications
How notifications reach the Android shade from a Cefrium app -- Web Notifications, Web Push and native FCM, each validated end to end on a device.
| Path | Status | Use it for |
|---|---|---|
Web NotificationsshowNotification() |
Works out of the box | Showing a notification from page or service-worker code. No Firebase, no setup. |
Web PushPushManager.subscribe() |
Works since 0.14.0 | production endpoint since 0.18.0 | Standards push code, in every profile, also when the app is not running. One manifest line, or one call from your own Firebase service. |
Web Push via UnifiedPushcefrium-unifiedpush |
Works since 0.15.0 | no Google | The same page code on devices without Google Play services, through the distributor the user chose (ntfy, NextPush). |
Web Push via your relayCefriumRelayTransport |
Works since 0.15.0 | your Firebase project | The same page code through your own Firebase project, with cefrium-relay, a stateless service you run. |
| Native FCM Firebase Cloud Messaging |
Production | validated | Delivering push to your app in production, via your own Firebase project. |
Does Cefrium require Google Play Services?
No. The engine - browsing, rendering, the ad-blocker, and Web Notifications display - runs without Google Play Services, including on de-Googled / AOSP devices. GMS is touched only by opt-in feature paths (native FCM push, WebOTP SMS autofill, passkey verification), and each degrades gracefully when GMS is absent.
One honest detail: the SDK depends on the Play services and
Firebase libraries Chromium uses, so they are in your app as ordinary Maven
dependencies. They stay inert unless your app opts into FCM with a
google-services.json. Native push (section 3) is the only path that
needs GMS on the device - and only your app turns it on.
1. Web Notifications - works out of the box
A page asks for permission and posts a notification through its service worker. No Firebase, no extra dependency - the display path lives entirely in the bundled engine.
// page.js
const reg = await navigator.serviceWorker.register('/sw.js');
if (await Notification.requestPermission() === 'granted') {
// `new Notification(...)` is an illegal constructor on Android --
// always go through the service-worker registration:
reg.showNotification('Hello from Cefrium', { body: 'It works.' });
}
Grant the permission natively - answer the prompt, or pre-grant per origin:
// Java / Kotlin (View API)
browser.setPermissionHandler((origin, permissions, cb) -> cb.respond(true));
// or, up front for a known origin:
browser.setContentSetting("https://example.com",
CefriumBrowser.PERMISSION_NOTIFICATIONS, CefriumBrowser.SETTING_ALLOW);
In Compose, the same call is on the navigator:
navigator.setContentSetting(origin, permission, value).
That is the whole integration. The Cefrium Gradle plugin already generates the R classes Chromium's notification code reads, so a standard SDK setup shows web notifications with nothing else added.
2. Web Push - works end to end (since 0.14.0)
The W3C Push API, with the app's Firebase setup as the transport:
const sub = await reg.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: <your VAPID public key>,
});
sub.endpoint; // https://fcm.googleapis.com/fcm/send/...
FCM delivers each message to the app, and the SDK hands it to the engine,
which wakes the page's service worker in the profile that subscribed. An app
without a FirebaseMessagingService of its own enables the SDK's,
which ships disabled:
<service android:name="com.cefrium.CefriumPushService"
android:enabled="true" tools:replace="android:enabled" />
An app with its own service passes every message through
CefriumPush.handleMessage, which takes the Web Push ones and
returns false for the app's own:
public void onMessageReceived(RemoteMessage message) {
if (CefriumPush.handleMessage(this, message.getFrom(),
message.toIntent().getExtras())) {
return;
}
// The app's own message.
}
If the app is not running, the message starts it. A subscription of the default profile is delivered at once, in the background; one of a named profile is kept until the app opens that profile. Before 0.14.0 the SDK had no receiver, so messages reached the device and went nowhere.
For about a minute after a page subscribes, FCM can answer 410 now and then, and accept the same subscription a few seconds later. Chrome gets this too. A server drops a subscription on 410, so a server that pushes soon after a user subscribes should retry a 410 that comes within the first minute, with a few seconds between tries, before it drops the subscription.
The endpoint
Chromium picks the endpoint from the build's release channel: a stable
build gets FCM's production endpoint, fcm.googleapis.com, and
any other build gets a staging one. Before 0.18.0 the SDK was built without
a channel, so its subscriptions got FCM's staging endpoint
(jmt17.google.com, before that /preprod/wp/).
Staging delivered in all our tests, but Google documents no availability
commitment for it. Since 0.18.0 the SDK is a stable build. The endpoint is
made from the subscription each time the page reads it, so after the update
getSubscription() returns the production endpoint for the
same subscription. A server keeps whatever endpoint it stored, so have the
page send its subscription again after the update. An app that wants a
service of its own can use its own Firebase project through a relay or
UnifiedPush (both below), another push service through
CefriumPushTransport, or native FCM.
Through your own Firebase project: cefrium-relay (since 0.15.0)
cefrium-relay is a Web Push service you run (a single Go
binary, source in cefrium_relay/ of the engine repository). It
delivers through your app's Firebase project and keeps no state: each endpoint
carries the subscription, the app's FCM token and the page's VAPID key,
encrypted on the device to the relay's key. The relay checks the sender's
VAPID signature and forwards the message, still encrypted for the page,
through FCM.
// On your server
cefrium-relay keygen -key relay-key.pem # prints the public key
cefrium-relay -origin https://push.example.com -key relay-key.pem \
-service-account service-account.json # a key of your Firebase project
// Application.onCreate()
CefriumPush.setTransport(new CefriumRelayTransport(
"https://push.example.com", "<public key printed by keygen>"));
Messages arrive through your FirebaseMessagingService, so keep
CefriumPushService enabled or call
CefriumPush.handleMessage from your own service. Pages must
subscribe with an applicationServerKey. A message of up to 4096
bytes is accepted; one over FCM's data limit travels in two parts that the SDK
joins. Validated end to end on a phone with real FCM, with the app open and
closed, in the default and a named profile. Sample:
cefrium-sample/push-demo built with -PrelayOrigin
and -PrelayKey.
Without Google Play services: UnifiedPush (since 0.15.0)
With com.cefrium:cefrium-unifiedpush, subscriptions are
registered with the UnifiedPush distributor on the device instead of FCM. The
page code does not change; its endpoint is the distributor's server, for
example https://ntfy.sh/up..., and application servers send to it
as to any Web Push endpoint. Messages stay encrypted for the page until the
engine decrypts them.
// build.gradle
implementation 'com.cefrium:cefrium-unifiedpush:0.21.0'
// Application.onCreate()
CefriumUnifiedPush.install(this);
// Once, from an Activity: the chosen distributor, or let the user pick one.
UnifiedPush.tryUseCurrentOrDefaultDistributor(activity, ok -> kotlin.Unit.INSTANCE);
Until a distributor is chosen, subscribe() fails with an
AbortError. ntfy answers 507 for a few seconds after a new
subscription, until the distributor has connected to it, so a server that
pushes at once should retry. Validated end to end on a device without any
Google Play services and on a phone, with the app open and closed, in the
default and a named profile. Sample:
cefrium-sample/unifiedpush-demo.
Any other push service plugs in the same way: extend
CefriumPushTransport, return the endpoint from
subscribe(), and pass each message body to
CefriumPush.deliverMessage.
Subscriptions survive the app being killed (0.16.0)
Android kills apps whenever it needs memory. A subscription made or removed shortly before that could break: the new one stopped receiving, or the next one reused an ID the push service had already deleted and never received anything. The engine now writes a subscription's record to disk before it confirms the subscription to the page or deletes it on the push service. Each release runs three subscribe-and-unsubscribe rounds per profile and a two-site case through FCM on a phone, and the on-device suite checks the record is on disk at both points.
3. Native FCM - the production path
Native FCM uses the device's Google Play Services to register and deliver, so it is on production GCM regardless of the engine's identity.
Validated end-to-end. On a Play-certified emulator, a Cefrium app's Firebase setup returned a real FCM token, and a push sent via FCM HTTP v1 was received and shown in the notification shade.
Gradle - as in any app
Since release 0.12, Firebase is set up exactly as in an app without Cefrium. The SDK
no longer carries its own copy of the Firebase classes, so
firebase-messaging brings its manifest entries (component
discovery, receiver, messaging service) and there is nothing to declare by
hand.
plugins {
id 'com.android.application'
id 'com.cefrium'
id 'com.google.gms.google-services' // injects google-services.json
}
dependencies {
implementation 'com.cefrium:cefrium-sdk:0.21.0'
implementation platform('com.google.firebase:firebase-bom:34.4.0')
implementation 'com.google.firebase:firebase-messaging'
}
Add your google-services.json to the app module; its
package_name must equal your applicationId. Declare
POST_NOTIFICATIONS to show notifications on Android 13 and later.
Upgrading from 0.11 or earlier: remove the
ComponentDiscoveryService, FirebaseInstanceIdReceiver and
FirebaseMessagingService entries you copied into your manifest, and the
okio and guava exclusions.
Get the token, send a push
com.google.firebase.messaging.FirebaseMessaging.getInstance().getToken()
.addOnCompleteListener(t -> {
if (t.isSuccessful()) Log.i(TAG, "FCM_TOKEN=" + t.getResult());
});
# Send via FCM HTTP v1 (service-account OAuth)
ACCESS=$(gcloud auth print-access-token)
curl -s -X POST -H "Authorization: Bearer $ACCESS" -H "Content-Type: application/json" \
"https://fcm.googleapis.com/v1/projects/<PROJECT_ID>/messages:send" \
-d '{"message":{"token":"<FCM_TOKEN>",
"notification":{"title":"Cefrium FCM","body":"Native delivery works"}}}'
Play-certified device required.
getToken() goes through Play Services' GCM registration, which only
completes on a certified device. On uncertified hardware (and on
emulator images without the Play Store) it hangs - while
FirebaseInstallations.getId() still works. If getToken()
never returns, that is your device's GMS, not Cefrium. Use a certified phone or a
google_apis_playstore emulator image. On Android 13+, also grant
the runtime POST_NOTIFICATIONS permission or the message is dropped
silently.
Full working sample
The push-demo in cefrium-sample wires all three paths, with a complete manifest, the Gradle exclusions, and token retrieval. Its README is the in-depth reference.