Navigator:deviceMemory 属性

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

安全上下文: 此项功能仅在一些支持的浏览器安全上下文(HTTPS)中可用。

Navigator 接口的只读属性 deviceMemory 返回设备内存的近似值(以千兆字节为单位)。

为了防止指纹识别,报告的值并不精确。该值通过向下取整到最接近的 2 的幂,然后将其除以 1024 来近似。之后,将其限制在上下限范围内,以保护内存非常低或非常高的设备的所有者的隐私。

一个浮点数;取值范围为 0.250.51248

示例

js
const memory = navigator.deviceMemory;
console.log(`此设备至少拥有 ${memory}GiB 的 RAM。`);

规范

Specification
Device Memory
# sec-device-memory-js-api

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
deviceMemory

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

参见