Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

e.$OneSignal.on is not a function for Nuxtjs PWA - OneSignal

I'm using @nuxtjs/pwa along with @nuxtjs/onesignal. I'm having an issue with listener to the subscriptionChange event on mounted. It's working very well with localhost, the issue is happened on production.

mounted() {
  let self = this;
  this.$OneSignal.push(() => {
  self.$OneSignal.on('subscriptionChange', (isSubscribed) => {
    if (isSubscribed) {
      self.$OneSignal.getUserId().then((deviceId) => {
        self.addDeviceId(deviceId)
      });
     }
    });
  });
}

On production error: enter image description here

Thank you and appreciate.

like image 726
CHHUM Sina Avatar asked Dec 10 '25 20:12

CHHUM Sina


1 Answers

Fortunately, I had these issues some hours back you need to access Onesignal using the global window method

window.OneSignal = window.OneSignal || []
window.OneSignal.push(() => {
  window.OneSignal.on('subscriptionChange', (isSubscribed) => {
    if (isSubscribed) {
      window.OneSignal.getUserId().then((deviceId) => {
        self.addDeviceId(deviceId)
      });
    }
  });
})
like image 73
nitrocode Avatar answered Dec 14 '25 03:12

nitrocode



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!