EddyVerbruggen / Insomnia-PhoneGap-Plugin

:sleepy: Prevent the screen of the mobile device from falling asleep
264 stars 106 forks source link

TypeError: 'undefined' is not an object (evaluating 'window.plugins.insomnia') #7

Closed kalepail closed 10 years ago

kalepail commented 10 years ago

Hey, loving this little plugin, but ran into a bug when in development. It's working like a charm once you're on the phone but is throwing an error when building in development on a non phone server.

It's throwing the TypeError: 'undefined' is not an object (evaluating 'window.plugins.insomnia') I assume this has something to do with newer versions of Cordova not building out the JS or something. Any ideas for a fix or work around so I can get back to developing without having to comment this line out all the time?

EddyVerbruggen commented 10 years ago

Hi Tyler,

This is quite normal behaviour because plugins can't be used when not on a device or decent emulator.

The best thing to do is only calling the plugin when window.plugins !== undefined

Hope this makes sense, Eddy