Fix bug (trying to get user agent in non-UI context)