57

I need to get any information about the CPU/GPU/memory.The number of cores, memory value, memory and cpu usage... I found a way to do this for IE:How to Use JavaScript to Find Hardware Information

solutions for other browsers I do not know. Any idea how to do it? maybe webgl has access to information about your computer? or flash? or any other technology?

Thank you very much

3
  • 2
    In google chrome you can use console.memory to find out the amount of memory available in the JS heap. Commented Mar 17, 2013 at 19:01
  • I'd have a look at whether a Flash shim might help. I haven't seen any cross-browser API for hardware info before. Commented Mar 17, 2013 at 19:02
  • Those methods no longer work in IE. Browsers are trying to make it harder to track people. One way to track people is to look up all the info about their machine. That plus their ip address is often enough to identify someone or a least a specific machine. So, browser don't show CPU/GPU/Memory/# cores/etc. (panopticlick.eff.org) Commented Mar 18, 2013 at 15:32

3 Answers 3

40

This code will print GPU info and will list all info you can get from the Performance object of this browser (it's different for each browser).

<html> <body> <canvas id="glcanvas" width="0" height="0"></canvas> <script> var performance = window.performance || window.mozPerformance || window.msPerformance || window.webkitPerformance || {}; const performanceKeys = []; for (var value in performance) { performanceKeys.push(value); } document.write("<br>"); document.write(performanceKeys.sort().map((p) => '<a href="https://developer.mozilla.org/en-US/docs/Web/API/Performance/' + p + '">' + p + "</a>").join("<br>")); document.write("<br>"); document.write("<br><br><br>"); var canvas; canvas = document.getElementById("glcanvas"); var gl = canvas.getContext("experimental-webgl"); document.write(gl.getParameter(gl.RENDERER) + "<br>"); document.write(gl.getParameter(gl.VENDOR) + "<br>"); document.write(getUnmaskedInfo(gl).vendor + "<br>"); document.write(getUnmaskedInfo(gl).renderer + "<br>"); function getUnmaskedInfo(gl) { var unMaskedInfo = { renderer: '', vendor: '' }; var dbgRenderInfo = gl.getExtension("WEBGL_debug_renderer_info"); if (dbgRenderInfo != null) { unMaskedInfo.renderer = gl.getParameter(dbgRenderInfo.UNMASKED_RENDERER_WEBGL); unMaskedInfo.vendor = gl.getParameter(dbgRenderInfo.UNMASKED_VENDOR_WEBGL); } return unMaskedInfo; } </script> </body>

Output in Chrome:

addEventListener clearMarks clearMeasures clearResourceTimings dispatchEvent eventCounts getEntries getEntriesByName getEntriesByType mark measure memory navigation now onresourcetimingbufferfull removeEventListener setResourceTimingBufferSize timeOrigin timing toJSON WebKit WebGL WebKit NVIDIA Corporation NVIDIA GeForce GTX 775M OpenGL Engine 

Output in Firefox:

addEventListener clearMarks clearMeasures clearResourceTimings dispatchEvent eventCounts getEntries getEntriesByName getEntriesByType mark measure navigation now onresourcetimingbufferfull removeEventListener setResourceTimingBufferSize timeOrigin timing toJSON Mozilla Mozilla 

Output in Safari:

addEventListener clearMarks clearMeasures clearResourceTimings dispatchEvent getEntries getEntriesByName getEntriesByType mark measure navigation now onresourcetimingbufferfull removeEventListener setResourceTimingBufferSize timeOrigin timing toJSON WebKit WebGL WebKit NVIDIA Corporation NVIDIA GeForce GTX 775M OpenGL Engine 
Sign up to request clarification or add additional context in comments.

3 Comments

detects Nvidia Geforce GTX 960M (laptop) as GTX 980 (desktop)
If you're interested in this question, you may like to know that Firefox has started "bucketing" GPU names -- quite a lot of GPUs now show up as "GTX 980". It's an anti-fingerprinting measure.
These days the only difference is that Chrome has performance.memory (deprecated) and Safari doesn't have performance.eventCounts.
15

Currently Chrome Canary supports returning the amount of CPU cores using:

navigator.hardwareConcurrency 

This worked for me in Chrome Canary 37.

6 Comments

Works in Chrome 40 stable.
I wrote about hardwareConcurrency in other browsers here: stackoverflow.com/a/31896597/1026
Is this cores or threads? Because when I did this I got the number 4 back, but my processor only has two cores (it does have 4 threads though). I'm guessing this is because I have an i7?
According to wiki.whatwg.org/wiki/Navigator_HW_Concurrency it returns the number of logical processors available to the user agent, up to an optional thread limit per origin.
@Johannes with processors supporting Hyperthreading the system sees your double core processor as quad core. Not browsers only, but OS itself.
|
12

Estimate CPU speed by timing how long it takes to decrement a variable millions of times:

const runs = 150000000; const start = performance.now(); // in ms, usually with 100us resolution for (let i = runs; i>0; i--) {} const end = performance.now(); const ms = end - start; const cyclesPerRun = 2; const speed = (runs / ms / 1000000) * cyclesPerRun; console.log(`Time: ${Math.round(ms)/1000}s, estimated speed: ${Math.round(speed*10)/10} GHz`); 

* cyclesPerRun is a very rough way to map "subtractions per second" to clock speed and it varies a lot across browsers (because their JavaScript engines might optimize the code differently) and CPUs (because they might be able to pipeline more instructions, they might ramp up their frequency faster, etc.). You might be better off just using runs / ms as a generic "CPU speed" parameter instead of trying to estimate the clock speed in GHz with cyclesPerRun.

You can also estimate cyclesPerRun yourself by running the code above on a CPU you know the clock speed of and then doing this:

const knownSpeed = 3.2; // GHz const estimatedCyclesPerRun = knownSpeed / (runs/ms/1000000); console.log("cyclesPerRun = " + estimatedCyclesPerRun); 

Also this benchmark depends on the number of browser tabs the user has open or if some other program (like a video game) is already using the computer's resources, etc.

18 Comments

Well.. I guess it's accurate if you tweak the _speedconstant for "your" machine, because running this in my 4-year-old machine estimates 23.753GHz. This is also susceptible to javascript engine optimizations.
@olivarra1 Yep, it is not the most reliable, but I found that it is good for a quick client-side approximate estimate of CPU speed, for mobile devices especially. I have used it in the past when other solutions like the first one fail, or when the browser cannot be identified. I can see your point though, it doesn't really work on PCs with JS optimizations or multiple cores :)
Yes, that's definitely better than nothing.... I will consider the output of this method as a generic "JS speed value" more than the GHz of the processor, which is more than enough to optimize the app to the power of the machine.
@olivarra1 Good idea :)
I'm also getting 7.89Ghz on a processor that boosts up to 4.9Ghz but usually runs at more like 3.7 (i9-11950H). It's worth noting that most modern processors have highly variable speeds. It seems like thie benchmark constant needs a /2 somewhere at the end because of some perf improvement in V8 perhaps? e.g. var _speedconstant = 4.5e-9; gives 3.75Ghz for me, which is a lot closer to realistic, but would need to profile on several CPUs to test. Of note it works if I 4x the amount val, but if I 8x it, it goes way off and estimates 0.58Ghz. Also: would be ideal to run this in a webworker.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.