Instructions pour activer les notifications push
📧 Étape 1 : Contacter le support Base44
Envoyez un email au support Base44 avec le modèle ci-dessous :
Objet: Demande de placement du fichier firebase-messaging-sw.js Bonjour l'équipe Base44, Je souhaite activer les notifications push sur mon application NANLÈLÈ. Pourriez-vous placer le fichier ci-joint "firebase-messaging-sw.js" à la racine de mon domaine ? Emplacement requis: https://[mon-domaine]/firebase-messaging-sw.js Le fichier est joint à cet email. Merci d'avance ! Cordialement
📄 Étape 2 : Joindre ce fichier
Nom du fichier : firebase-messaging-sw.js
importScripts('https://www.gstatic.com/firebasejs/9.22.0/firebase-app-compat.js');
importScripts('https://www.gstatic.com/firebasejs/9.22.0/firebase-messaging-compat.js');
firebase.initializeApp({
apiKey: "AIzaSyBGLoQxiySk-W05FL9gbblUNb1hJclUmI8",
authDomain: "nanlele-notifications.firebaseapp.com",
projectId: "nanlele-notifications",
storageBucket: "nanlele-notifications.firebasestorage.app",
messagingSenderId: "1071966951029",
appId: "1:1071966951029:web:7086f01bac218d877c8a3c"
});
const messaging = firebase.messaging();
messaging.onBackgroundMessage((payload) => {
console.log('Message reçu en arrière-plan:', payload);
const notificationTitle = payload.notification?.title || 'NANLÈLÈ';
const notificationOptions = {
body: payload.notification?.body || 'Nouvelle notification',
icon: '/icon-192.png',
badge: '/icon-192.png',
vibrate: [200, 100, 200],
data: {
url: payload.notification?.click_action || payload.data?.url || '/'
}
};
return self.registration.showNotification(notificationTitle, notificationOptions);
});
self.addEventListener('notificationclick', (event) => {
console.log('Notification cliquée:', event);
event.notification.close();
const urlToOpen = event.notification.data?.url || '/';
event.waitUntil(
clients.matchAll({ type: 'window', includeUncontrolled: true })
.then((windowClients) => {
for (let i = 0; i < windowClients.length; i++) {
const client = windowClients[i];
if (client.url === urlToOpen && 'focus' in client) {
return client.focus();
}
}
if (clients.openWindow) {
return clients.openWindow(urlToOpen);
}
})
);
});⚠️ Important
- Le fichier doit être placé à la racine :
https://votre-domaine.com/firebase-messaging-sw.js - Ne pas le placer dans un sous-dossier
- Une fois placé, les notifications hors ligne fonctionneront automatiquement
✅ Comment télécharger le fichier à envoyer
- Cliquez sur le bouton ci-dessus pour copier le code
- Ouvrez un éditeur de texte (Notepad, VS Code, etc.)
- Collez le code copié
- Enregistrez le fichier avec le nom :
firebase-messaging-sw.js - Joignez ce fichier à votre email au support Base44