onesignal-module icon indicating copy to clipboard operation
onesignal-module copied to clipboard

OneSignal instance is not consistant, when reloading the page

Open julianschmuckli opened this issue 3 years ago • 1 comments

I try to implement the module in my Nuxt page. But it seems it does not work properly every time.

I have setup the nuxt.config.js as follow:

  // One Signal
  oneSignal: {
    init: {
      appId: "****",
      safari_web_id: "web.onesignal.auto.****",
      allowLocalhostAsSecureOrigin: true,
      welcomeNotification: {
        disable: true
      },
      promptOptions: {
        slidedown: {
          prompts: [
            {
              type: "category",
              autoPrompt: true,
              text: {
                actionMessage:
                  "Abonniere verschiedene Themen von ABC und bleibe auf dem Laufenden.",
                acceptButton: "Abonnieren",
                cancelButton: "Später",

                /* CATEGORY SLIDEDOWN SPECIFIC TEXT */
                negativeUpdateButton: "Abbrechen",
                positiveUpdateButton: "Aktualisieren",
                updateMessage:
                  "Ändere dein Abonnement um verschiedene Themen von ABC zu erhalten."
              },
              delay: {
                pageViews: 2,
                timeDelay: 20
              },
              categories: [
                {
                  tag: "portfolio",
                  label: "Portfolio"
                },
                {
                  tag: "projects",
                  label: "Projekte"
                },
                {
                  tag: "general",
                  label: "Generell"
                }
              ]
            }
          ]
        }
      }
    }
  },
  // .....
  modules: [
    // https://go.nuxtjs.dev/axios
    "@nuxtjs/axios",
    "@nuxtjs/onesignal",
    "@nuxtjs/pwa",
    ["vue-scrollto/nuxt", { duration: 300 }]
  ],

And there is an method where I want to show the category slidedown:

async open() {
    console.log(this.$OneSignal)
    try {
        await this.$OneSignal.showCategorySlidedown({ force: true });
    } catch (e) {
        console.error(e);
    }
},

Because when it works, the output of this.$OneSignal instance is: class Bi{static setDefaultNotificationUrl(e){return Object(d.a)(this,void 0,void 0,function*(){if(!Ri.isValidUrl(e,{allowNull:!0}))throw new InvalidArgumentError.a("url",InvalidArgumentError.b.Malformed);y…

Now when I reload the page and the showCategorySlidedown function does not work, but does not give any warning. Instead I checked the instance again and it looks like an other instance. OneSignalStubES6 {VERSION: 151508, log: {…}, directFunctionCallsArray: Array(0), preExistingArray: Array(1), on: ƒ, …}

julianschmuckli avatar Oct 10 '21 19:10 julianschmuckli

Sat Sri Akal ji I ran into many issues with this module

ended up doing typical install onesignal https://documentation.onesignal.com/v7.0/docs/web-push-typical-setup

and changed scope of onesignal service worker https://documentation.onesignal.com/docs/onesignal-service-worker-faq#customizing-your-service-worker-integration

also adding one signal script in nuxt application head through app.html https://github.com/gpmkc-moga/gpmkc-moga.github.io/blob/972718a9c59c466d5a494e5584fe85ef870894cc/app.html#L5

hope this helps someone!

cingh-jasdeep avatar May 21 '22 11:05 cingh-jasdeep