Notification JS functions not working in background

I am using FCM notifications, I execute Howl js to play a sound and an alert() when a notification arrives, everything works perfectly but when my page is in the background, or in another tab it does not execute the Howl js function, it only arrives the system notification. How could I run functions in the background?

const messaging = firebase.messaging();

navigator.serviceWorker.register("{{url('firebase/sw-js')}}")
            .then((registration) => {
                messaging.useServiceWorker(registration);
                messaging.requestPermission()
                    .then(function() {
                        console.log('Notification permission granted.');
                        getRegToken();

                    })
                    .catch(function(err) {
                        console.log('Unable to get permission to notify.', err);
                    });
 

messaging.onMessage(function(payload) {

                    const notificationTitle = payload.data.title;
                    const notificationOptions = {
                        body: payload.data.body,
                        icon: payload.data.icon,
                        image:  payload.data.image,
                        requireInteraction : true
                    };
                                      
                    var notification = new Notification(notificationTitle,notificationOptions);
                    console.log("Message received. ", payload);


                    notification.addEventListener('show', (event) => {
                        console.log('Notification ');
                        audio.play();
                    });

                    notification.addEventListener('close', (event) => {
                        audio.stop();
                    })
                    
                });
               
            });


 var audio = new Howl({
                    src: ["{{asset('notification.mp3')}}",'notification.webm'],
                    onplayerror: function(){
                        audio.once('unlock',function(){
                            audio.play();
                        });
                    },
                    html5:true,
                    loop: true,
                    preload:true,
            });

How could I run functions in the background?,If the user allows notifications to the website, why doesn’t it run in the background?