use btoa as base64 encoder, inspired by @ashtuchkin
fixed lineno
safer browser check