Window["plugins"] is null! so I can't start onesignal

Hello :slight_smile:

I start my app with onesignal .

but sometimes window[“plugins”] value is undefined so it goes to error screen…
how can I prevent from getting window[“plugins”] is undefined?

  window["plugins"].OneSignal
        .startInit("xxxx", "xxxxx")
        .handleNotificationOpened(function(jsonData) {
          console.log(jsonData.notification.payload.additionalData.datas)
        })
        .endInit();

Hi @pdj :wave:

You need to wait for the plugins to finish loading by listening to the “deviceready” event from Cordova before using any plugin. In Ionic Angular you can do this easily with the platform.ready() promise.

But I strongly recommend you to use OneSignal from Ionic Native, since it’s easier to deal with plugins and you’ll get type autocompletion and better error messages.

Best,
Rodrigo

Wrap it in platform.ready() and make sure you aint testing through your browser