Web console and PHP relay for exercising Firebase Cloud Messaging (FCM) push notifications with optional APNs payload fields.
Building custom Firebase notifications usually means guessing at the payload, sending it, and checking a phone to see what arrived. This console lets you write a notification (title, body, image, data JSON, priority), send it to specific browser or mobile device tokens, and see right away how it shows up on screen or on the device, along with the exact payload that was received.
It also works as reference code for the whole flow: registering the browser and its service worker for notifications, managing device tokens, and a PHP relay that sends messages through the FCM HTTP v1 API using short-lived OAuth tokens from a service account.
- Serve the console over HTTPS (trusted cert or
http://localhostfor local dev) because Firebase Messaging requires a secure origin.
- From the
ext/directory runcomposer install. - The
ext/vendor/directory is ignored in Git; rerun the command after cloning or whenever dependencies change.
- Sign in at https://console.firebase.google.com/ and create/select a project.
- Add a Web app, then copy the Firebase project settings to
cfg/config.php.
The steps below produce the service account key required to mint the short-lived OAuth 2.0 access token (rotated roughly every 1800s) that authenticates requests to the Firebase v1 send API.
- Open Firebase Console: https://console.firebase.google.com
- Select your project.
- Click the gear icon next to "Project Overview" and choose "Project settings".
- Open the "Service accounts" tab.
- Under "Firebase Admin SDK", click "Generate new private key".
- Downloaded key file will be saved locally.
- Place the key file in
cfg/gcloud/service_account_keys/. - Reference the filename in
cfg/config.phpvia$config['firebase']['service_account_key'].
- Available at
/console/; registers browser tokens and triggers test notifications viapush_notifications.php. - Firebase web setup pulls config from
console/config_js.phpso secrets stay outside the repo (cfg/config.php). - Console UI lets you enter device tokens, title/body/image/data JSON, priority, and previews the payload.
- FCM targeting: only
tokenis supported today;topicandconditiontargets are not yet implemented.
In some local or test setups, Chrome may fail to register the service worker with an error such as:
Service worker registration failed: An SSL certificate error occurred when fetching the script.
This happens when the app is served over HTTPS with a self-signed or otherwise untrusted certificate. Chrome only allows service workers on fully trusted secure origins, so if the certificate is not trusted by the operating system, Chrome treats the connection as insecure and blocks service worker registration. Manually bypassing the HTTPS warning is not enough; the certificate must be trusted at the OS level.
Workarounds:
- Use
http://localhostfor development (Chrome treats it as a secure context), or - Install the self-signed/CA certificate into the system’s trusted root store so Chrome accepts the HTTPS origin as valid.
- Use Firefox for local testing, which is more permissive with manually accepted self-signed certificates (though trusting the certificate at the OS level is still recommended).
MIT Licence
