Fixed JS error with user agent detection