Ionic global window.plugin undefined, but visible in log of just window

Okay, so I’m trying to use a Cordova plugin.

If I use console.log(window) my plugin is visible

However, if I try console.log(window.myPlugin) I receive an undefined message.

So obviously, later in my app, when I try window.myPlugin.DoSomeThing(), it doesn’t work.

I know that I’m missing something super simple, but for the life of me I can’t find it.

When exactly do you do these console.log? Can you just click on the myPlugin in the first instance and see what is in there? Maybe provide screenshots…

1 Like

Yes, I can click on it in the first instance and see all of its methods.

However, when I try calling any of those methods, nothing works.

ionViewDidLoad(){
   console.log(window);
   console.log(window.OT);

   window.OT.initPublisher();
}

console.log(window)
console.log(window.OT) -> Undefined

window.OT.initPublisher(); -> cannot read property ‘initPublisher’ of undefined

Capture1

1 Like

Try to wrap all that code in platform.ready. It may be that you expanding window happens at runtime, not with the data when it was executed. So it was missing back then, is not missing now any more. You can also just call console.log(window.OT) in the console (blue > at the bottom of the console output)