add defensive checks before calling cordova APIs