mumuy / browser

浏览器检测 - Useragent分析/浏览器识别/浏览器判断/UA解析/用户代理信息/Useragent analysis tool/Browser detection
https://passer-by.com/browser/
MIT License
1.51k stars 326 forks source link

doesnt support nodejs? #12

Closed ghost closed 6 years ago

ghost commented 6 years ago

Below is your comments on the top of the code

/**
 * 浏览器解析,浏览器、Node.js皆可
 * https://github.com/mumuy/browser
 */

I use this script on NodeJs,but var _window = window||{}; throw error,window is not defined.

ghost commented 6 years ago
if(_window.showModalDialog && _window.chrome ){
            var chrome_vision = u.replace(/^.*Chrome\/([\d]+).*$/, '$1');
            if(chrome_vision>36){
                is360 = true;
            }
        }
 var navigator_top = window.screenTop-window.screenY;

these codes cant run on nodejs.

onlyling commented 6 years ago

onlyling/browser

const BrowserInfo = require('./browser')

/**
 * 浏览器信息
 * @param  {[type]} userAgent      [description]
 * @param  {[type]} acceptLanguage [description]
 * @return {[type]}                [description]
 */
const getBrowserInfo = (userAgent, acceptLanguage) => {
    let info = new BrowserInfo(userAgent, acceptLanguage)

    // let infoArr = [
    //     '浏览器:' + info.browser,
    //     '版本:' + info.version,
    //     '内核:' + info.engine,
    //     '操作系统:' + info.os + info.osVersion,
    //     '设备:' + info.device,
    //     '语言:' + info.language,
    // ]
    // return infoArr.join('|')

    return info.browser + '/' + info.version
}

getBrowserInfo(req.headers['user-agent'], req.headers['accept-language']);
ghost commented 6 years ago

@onlyling six six six u forked this script and expand it 2 support node?

mumuy commented 6 years ago

应该解决了