How to access OneSignal web push notifications data in order to perform other actions

I’m trying to access OneSignal web push notification data to update other parts of my website. However, the on(‘notificationDisplay’) or on(‘notificationDismiss’) events are not being triggered. My website is served over HTTPS, so that shouldn’t be the issue. Here’s my current implementation:

<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.onesignal.com/sdks/OneSignalPageSDKES6.js?v=151606" async=""></script>
  <script>
    var onesignalAppId = "1234567890";
    var idWriter = "12345";
    var OneSignal = window.OneSignal || [];

    if (onesignalAppId) {
      OneSignal.push(function() {
        OneSignal.init({
          appId: onesignalAppId,
          notifyButton: { enable: true },
          logLevel: 'trace'  // Enable verbose logging
        });

        OneSignal.showNativePrompt();

        OneSignal.on('notificationDisplay', function(event) {
          console.log('OneSignal notification displayed:', event);
          alert(event);
        });

        OneSignal.on('notificationDismiss', function(event) {
          console.log('OneSignal notification dismissed:', event);
        });

        OneSignal.on('subscriptionChange', function(isSubscribed) {
          console.log('Subscription changed:', isSubscribed);
        });

        if (idWriter) {
          OneSignal.setExternalUserId(idWriter);
        }
      });
    }
  </script>
</head>
<body>
  Content
</body>
</html>

I’ve seen similar questions suggesting that these events only work on HTTPS sites, but my site is indeed HTTPS. What could be the problem?

Are there any common issues or additional configurations that I might be missing? Any help would be appreciated.