Now that we are modifying this code, we could get ride of the problem that we have in desktop and b2g for desktop that navigator.mozMobileConnection is null and we get an error

I know that are more lines of code but checking for navigator.mozMobileConnection being null will help on debugging in desktop.