OneSignal / onesignal-vue3

Vue 3 OneSignal Plugin: Make it easy to integrate OneSignal with your Vue App!
Other
19 stars 5 forks source link

[Question]: Not able to receive push notification when WebApp is active, Am I missing something ? #41

Open aman-u-7span opened 3 months ago

aman-u-7span commented 3 months ago

Not able to receive push notification when WebApp is active, Am I missing something ?

I'm not able to receive notification when tab is active or when I'm on another tab. I'm getting notification only if my tab/website is completely closed. I'm facing same in my PWA as well. When PWA app and website is closed I'm able to receive notification. Am I missing anything ?

main.js

import OneSignal from '@onesignal/onesignal-vue3'

app.use(OneSignal, {
  appId: import.meta.env.VITE_ONE_SIGNAL_APP_ID,
  notifyButton: {
    enable: true
  },
  allowLocalhostAsSecureOrigin: true
})

My one-signal composable

      const isPushNotificationSupported = oneSignalApp.Notifications.isPushSupported()

      await oneSignalApp.Notifications.requestPermission()

      if (
        isPushNotificationSupported &&
        oneSignalApp.Notifications.permission &&
        oneSignalApp.Notifications.permissionNative === 'granted'
      ) {
        /// Here goes my code to save player_id in backend
       }

Package versions

"@onesignal/onesignal-vue3": "^2.0.1", "vue": "^3.3.11"

Service worker

/public/OneSignalSDKWorker.js -> importScripts("https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.sw.js");

Any help would be really appreciated. Thanks