Fix critical error in target device javascript

This fixes javascript errors which cause the script to fail and results in targets never finding the weinre server.