function printSystemInfo() {
// print system info
let ua = navigator.userAgent,
logMsg = '';
// device & system
let ipod = ua.match(/(ipod).*\s([\d_]+)/i),
ipad = ua.match(/(ipad).*\s([\d_]+)/i),
iphone = ua.match(/(iphone)\sos\s([\d_]+)/i),
android = ua.match(/(android)\s([\d\.]+)/i);
logMsg = 'Unknown';
if (android) {
logMsg = 'Android ' + android[2];
} else if (iphone) {
logMsg = 'iPhone, iOS ' + iphone[2].replace(/_/g,'.');
} else if (ipad) {
logMsg = 'iPad, iOS ' + ipad[2].replace(/_/g, '.');
} else if (ipod) {
logMsg = 'iPod, iOS ' + ipod[2].replace(/_/g, '.');
}
let templogMsg = logMsg;
// wechat client version
let version = ua.match(/MicroMessenger\/([\d\.]+)/i);
logMsg = 'Unknown';
if (version && version[1]) {
logMsg = version[1];
templogMsg += (', WeChat ' + logMsg);
console.info('[system]', 'System:', templogMsg);
} else {
console.info('[system]', 'System:', templogMsg);
}
}
printSystemInfo();
前端性能上报之准确获取当前系统信息,代码来自Vconsole源码
最新推荐文章于 2024-04-27 07:43:51 发布