I face the same problem, I fixed it by set click listener to call the function.
$(document).on('touchend click', function() {
requestNotificationPermission();
// Remove the event listener after the permission is requested
$(document).off('touchend click');
});
function requestNotificationPermission(){
firebase.initializeApp(config);
if (firebase.messaging.isSupported()){
const messaging = firebase.messaging();
messaging
.requestPermission()
.then(() => {
message.innerHTML = "Notifications allowed";
return messaging.getToken();