Georg Ledermann PRO said about 1 year ago on Push Notifications from Scratch :
Great episode, but while playing with the repo, I get an error in the browser console within Safari 16.3 on MacOS 13.2.1 and the notification does not work:

Notification prompting can only be done from a user gesture.

In other browsers (tested with Edge) there is just a warning, and the notification is displayed.

The error comes from startServiceWorker on the next visit after the notification was allowed. I changed the method (by removing the call of requestNotificationPermission()) to this and now it works fine:

async function startServiceWorker() {
  const vapidPublicKey = document.head
    .querySelector('meta[name="vapid_public_key"]')
    .getAttribute('content');
  await registerServiceWorker();

  const subscription = await getPushSubscription(vapidPublicKey);
  if (!subscription) return;

  await sendSubscriptionToServer(subscription);
}