web api instance property
WorkerNavigator: deviceMemory property
Secure contextAvailable in workers
The deviceMemory read-only property of the WorkerNavigator interface returns the approximate amount of device memory in gigabytes.
The reported value is imprecise to curtail fingerprinting. It’s approximated by rounding the actual value to the nearest power of 2, then dividing that number by 1024. It is then clamped within lower and upper bounds to protect the privacy of owners of very low-memory or high-memory devices. These bounds may change over time (see browser compatibility table).
Value
A floating point number coarsened to a power of two value, clamped to implement-defined limits.
For example, if a browser does not report below 2 or above 32 then the value is one of: 2, 4, 8, 16, 32.
Examples
The following code can be run in a worker:
const memory = navigator.deviceMemory;
console.log(`This device has approximately ${memory}GiB of RAM.`);
Specifications
Browser compatibility
See also
Sec-CH-Device-MemoryHTTP header