Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DeviceJS (RealDevice.js)

用于在浏览器环境中基于多维信号(输入能力、Web API、WebGL、UA 等)做设备/系统类型推断的轻量库。

功能概览

  • 检测目标系统:android、ios、ipados、macos、windows、linux
  • 返回各系统分值、Top 结果和置信度
  • 提供 WebGL、NFC 能力等辅助信息
  • 将检测结果写入全局变量 window.detectedOSType
  • 支持 ESM/CJS/IIFE 三种产物格式

安装与构建

pnpm install
pnpm build

构建后会在 dist 目录生成:

  • index.mjs(ESM)
  • index.cjs(CommonJS)
  • index.global.js(浏览器全局变量 window.RealDevice)
  • index.d.ts(类型声明)

快速使用

ESM

import DeviceInfoService from 'devicejs';
// 或: import { DeviceInfoService } from 'devicejs';

const service = new DeviceInfoService();
const result = await service.detect();
console.log(result);

浏览器 Script(IIFE)

<script src="./dist/index.global.js"></script>
<script>
  const service = new window.RealDevice.DeviceInfoService();
  service.detect().then((result) => {
    console.log(result);
    console.log(window.detectedOSType);
  });
</script>

API 说明

new DeviceInfoService()

创建检测服务实例。

await detect()

执行检测并返回:

{
  scores: Record<string, number>;
  top: string;
  confidence: number;
}

同时会更新:

  • 内部检测缓存
  • window.detectedOSType

getDetectionResult()

获取最近一次检测结果(未检测时可能为 null)。

getWebGL()

获取 WebGL 信息(vendor、renderer),不可用时返回 null。

getNFCCapabilities()

获取 NFC 能力探测结果(API 类型、可否扫描、异常信息等)。

getDeviceSignals()

获取设备信号对象(当前版本可能为 null,可按后续版本迭代)。

getDeviceType()

获取格式化后的设备类型字符串,如 Android、iOS、Windows。

getDeviceInfo()

获取完整设备信息汇总(检测结果、UA、屏幕信息、运行环境信息等)。

Examples

examples 目录下包含两个页面:

  • examples/full-feature-test.html

    • 全功能测试页
    • 覆盖导出校验、detect()、各 getter 调用
    • 输出 PASS/FAIL 测试摘要与详细日志
  • examples/demo.html

    • 展示型 Demo 页
    • 白日扁平化风格 UI
    • 展示检测结果、分值、完整设备信息与判据卡片

本地打开示例

建议通过本地静态服务器打开(避免部分浏览器策略影响能力探测):

# 示例:使用任意静态服务器工具
npx serve .

然后访问对应页面:

  • http://localhost:3000/examples/demo.html
  • http://localhost:3000/examples/full-feature-test.html

注意事项

  • 该库基于启发式多信号评分,不保证 100% 准确。
  • 隐私模式、浏览器安全策略、厂商定制内核会影响判据可见性。
  • 建议将结果用于“环境判断与适配”而非强安全场景。

About

检测真实设备信息,防止UA作弊 | Detect real device info to prevent UA cheating

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages