(async () => {
const ua = navigator.userAgent;
const uaData = navigator.userAgentData;
// 获取 User-Agent 高熵信息
let clientHints = {};
if (uaData?.getHighEntropyValues) {
try {
clientHints = await uaData.getHighEntropyValues([
"architecture",
"bitness",
"model",
"platform",
"platformVersion",
"fullVersionList",
"wow64"
]);
} catch (e) {}
}
// GPU 信息
function getGPU() {
const canvas = document.createElement("canvas");
const gl = canvas.getContext("webgl") ||
canvas.getContext("experimental-webgl");
if (!gl) return null;
const ext = gl.getExtension("WEBGL_debug_renderer_info");
return {
vendor: ext
? gl.getParameter(ext.UNMASKED_VENDOR_WEBGL)
: gl.getParameter(gl.VENDOR),
renderer: ext
? gl.getParameter(ext.UNMASKED_RENDERER_WEBGL)
: gl.getParameter(gl.RENDERER),
version: gl.getParameter(gl.VERSION),
shadingLanguage: gl.getParameter(
gl.SHADING_LANGUAGE_VERSION
),
maxTextureSize: gl.getParameter(gl.MAX_TEXTURE_SIZE)
};
}
// 网络信息
const connection =
navigator.connection ||
navigator.mozConnection ||
navigator.webkitConnection;
const network = connection ? {
effectiveType: connection.effectiveType,
downlink: connection.downlink,
rtt: connection.rtt,
saveData: connection.saveData
} : "浏览器不支持";
// 电池信息
let battery = "浏览器不支持";
if (navigator.getBattery) {
try {
const b = await navigator.getBattery();
battery = {
charging: b.charging,
level: `${Math.round(b.level * 100)}%`,
chargingTime: b.chargingTime,
dischargingTime: b.dischargingTime
};
} catch (e) {}
}
// 操作系统推断
let os = "Unknown";
if (/Macintosh|Mac OS X/.test(ua)) os = "macOS";
else if (/Windows/.test(ua)) os = "Windows";
else if (/Android/.test(ua)) os = "Android";
else if (/iPhone|iPad|iPod/.test(ua)) os = "iOS";
else if (/Linux/.test(ua)) os = "Linux";
// 浏览器推断
let browser = "Unknown";
if (/Edg\//.test(ua)) browser = "Microsoft Edge";
else if (/Chrome\//.test(ua)) browser = "Google Chrome";
else if (/Firefox\//.test(ua)) browser = "Firefox";
else if (/Safari\//.test(ua)) browser = "Safari";
// 屏幕信息
const screenInfo = {
width: screen.width,
height: screen.height,
availableWidth: screen.availWidth,
availableHeight: screen.availHeight,
colorDepth: screen.colorDepth,
pixelDepth: screen.pixelDepth,
devicePixelRatio: devicePixelRatio,
orientation: screen.orientation?.type
};
// 时区
const timezone = Intl.DateTimeFormat()
.resolvedOptions().timeZone;
const info = {
system: {
os,
platform: navigator.platform,
platformVersion: clientHints.platformVersion,
architecture: clientHints.architecture,
bitness: clientHints.bitness,
deviceModel: clientHints.model || "未暴露",
userAgent: ua
},
browser: {
name: browser,
userAgent: ua,
version: clientHints.fullVersionList ||
"可从 User-Agent 获取"
},
hardware: {
logicalCpuCores: navigator.hardwareConcurrency,
memoryGB: navigator.deviceMemory || "未暴露",
gpu: getGPU()
},
display: screenInfo,
network,
battery,
environment: {
language: navigator.language,
languages: navigator.languages,
timezone,
cookiesEnabled: navigator.cookieEnabled,
online: navigator.onLine,
touchPoints: navigator.maxTouchPoints
}
};
console.log("========== 设备信息检测结果 ==========");
console.table({
操作系统: info.system.os,
设备型号: info.system.deviceModel,
CPU架构: info.system.architecture,
CPU逻辑核心数: info.hardware.logicalCpuCores,
内存GB: info.hardware.memoryGB,
GPU: info.hardware.gpu?.renderer,
屏幕分辨率:
`${screen.width} × ${screen.height}`,
浏览器: info.browser.name,
时区: timezone
});
console.log("完整设备信息:");
console.log(info);
// 方便复制 JSON
const json = JSON.stringify(info, null, 2);
console.log("JSON 格式:\n" + json);
if (typeof copy === "function") {
copy(json);
console.log("设备信息 JSON 已复制到剪贴板");
}
return info;
})();