document.addEventListener('DOMContentLoaded', (event) => { function requestNotificationPermission() { if (Notification.permission !== "granted") { Notification.requestPermission(); } } function showNotification(title, body) { if (Notification.permission === "granted") { new Notification(title, { body }); } } requestNotificationPermission(); function handleMessageNotification(data) { const title = `New Message from ${data.sender}`; const body = data.content.length > 100 ? data.content.substring(0, 97) + '...' : data.content; showNotification(title, body); } window.notificationHandler = { handleMessageNotification }; });