How to Test Your Monitor with JavaScript: Dead Pixels, Refresh Rate, and Screen Resolution
When a CSS animation feels choppy, is it really a performance issue in your code? When a canvas looks blurry, is the problem your rendering logic or the device's pixel ratio? And when you buy a 144Hz monitor, how do yo
When a CSS animation feels choppy, is it really a performance issue in your code?
When a canvas looks blurry, is the problem your rendering logic or the device's pixel ratio?
And when you buy a 144Hz monitor, how do you know whether your browser is actually taking advantage of it?
Modern browsers expose several surprisingly useful APIs for understanding display behavior. You can measure frame timing, inspect screen resolution, render diagnostic patterns, and even investigate touchscreen dead zones without installing native software.
Let's explore how these techniques work and, more importantly, where their limitations are.
1. Reading Display Information with JavaScript
The browser provides basic display information through the window.screen object and window.devicePixelRatio.
const displayInfo = {
screenWidth: screen.width,
screenHeight: screen.height,
viewportWidth: window.innerWidth,
viewportHeight: window.innerHeight,
pixelRatio: window.devicePixelRatio,
colorDepth: screen.colorDepth
};
console.table(displayInfo);
One important distinction is that screen dimensions reported by the browser are expressed in CSS pixels, not necessarily physical hardware pixels.
For example, a display might report:
| Property | Value |
|---|---|
| Screen width | 1920 |
| Screen height | 1080 |
| Device pixel ratio | 2 |
| Estimated device pixel dimensions | 3840 × 2160 |
You can estimate the corresponding device pixel dimensions with:
const width = Math.round(
screen.width * window.devicePixelRatio
);
const height = Math.round(
screen.height * window.devicePixelRatio
);
console.log(`${width} × ${height}`);
However, browser zoom, operating system scaling, and privacy protections can affect these values. This calculation should not be treated as a guaranteed measurement of the panel's native resolution.
Understanding this distinction is particularly useful when working with Canvas, WebGL, responsive layouts, and high-DPI graphics.
2. Measuring Monitor Refresh Rate with requestAnimationFrame
JavaScript does not provide a universally supported API that directly returns the physical refresh rate of a monitor.
However, we can estimate the browser's frame callback rate using requestAnimationFrame().
Under normal conditions, its callback frequency is closely related to the display's active refresh rate.
Here's a simple implementation that measures frame intervals over five seconds:
function measureRefreshRate(duration = 5000) {
return new Promise((resolve) => {
const intervals = [];
let start;
let previous;
function frame(now) {
if (start === undefined) start = now;
if (previous !== undefined) {
intervals.push(now - previous);
}
previous = now;
if (now - start < duration) {
requestAnimationFrame(frame);
return;
}
intervals.sort((a, b) => a - b);
const mid = Math.floor(intervals.length / 2);
const median = intervals.length % 2
? intervals[mid]
: (intervals[mid - 1] + intervals[mid]) / 2;
resolve(1000 / median);
}
requestAnimationFrame(frame);
});
}
measureRefreshRate().then((hz) => {
console.log(`Estimated rate: ${hz.toFixed(2)} Hz`);
});
Using the median interval helps reduce the influence of occasional slow frames caused by scheduling delays.
Here are some typical frame intervals:
| Refresh rate | Frame interval |
|---|---|
| 60Hz | 16.67ms |
| 75Hz | 13.33ms |
| 120Hz | 8.33ms |
| 144Hz | 6.94ms |
| 165Hz | 6.06ms |
| 240Hz | 4.17ms |
This is also a useful reminder that rendering performance is relative to the display.
A frame that takes 12ms may be acceptable on a 60Hz display but can miss the frame budget on a 120Hz display.
There are several limitations to this approach:
- Background tabs may pause animation callbacks.
- Browser power-saving modes may reduce callback frequency.
- Heavy main-thread workloads can cause missed frames.
- Variable refresh rate displays may change their behavior dynamically.
- Browser and operating system compositors may impose additional limits.
The result represents observed browser frame timing, not a direct electrical measurement of the display hardware.
3. Building a Dead Pixel Test with HTML and JavaScript
Dead pixels are fundamentally a hardware problem.
A browser cannot directly inspect whether a physical pixel is emitting the correct color. What it can do is render controlled test patterns that make defects easier to see.
A basic dead pixel test cycles through solid colors:
- Red
- Green
- Blue
- White
- Black
Each color helps reveal different pixel or subpixel defects.
Here's a minimal implementation:
<button id="start">Start screen test</button>
<script>
const colors = [
"#ff0000",
"#00ff00",
"#0000ff",
"#ffffff",
"#000000"
];
let index = 0;
const button = document.getElementById("start");
function renderColor() {
document.body.style.background = colors[index];
}
button.addEventListener("click", async () => {
try {
await document.documentElement.requestFullscreen();
button.hidden = true;
renderColor();
} catch (error) {
console.error("Fullscreen unavailable:", error);
}
});
document.addEventListener("keydown", (event) => {
if (!document.fullscreenElement) return;
if (event.key === "ArrowRight") {
index = (index + 1) % colors.length;
} else if (event.key === "ArrowLeft") {
index = (index - 1 + colors.length) % colors.length;
} else {
return;
}
renderColor();
});
document.addEventListener("fullscreenchange", () => {
if (!document.fullscreenElement) {
button.hidden = false;
document.body.style.background = "";
}
});
</script>
Press the left and right arrow keys to change colors and inspect the screen. Press Escape to exit fullscreen.
A permanently dark point across bright test patterns may indicate a dead pixel, while a point that remains a particular color may indicate a stuck subpixel.
The distinction matters: some stuck pixels may recover, whereas physically damaged pixels generally cannot be repaired through software.
4. Why Screenshots Cannot Reliably Detect Dead Pixels
This is an interesting limitation of browser-based diagnostics.
Consider a simplified rendering pipeline:
JavaScript / CSS / WebGL
↓
Browser Rendering Engine
↓
GPU / Framebuffer
↓
Display Controller
↓
Physical Display Panel
A screenshot captures digital image data before the final physical output.
If a pixel on the actual monitor is defective, the screenshot may still contain the correct RGB values.
The same applies to several other display problems:
- LCD backlight bleed
- OLED burn-in
- Panel uniformity issues
- Pixel response-time ghosting
These problems often occur after the image has been rendered.
This is why a browser-based diagnostic tool should distinguish between programmatically measurable properties and visual tests that require human observation.
5. Testing Motion Ghosting
Refresh rate and pixel response time are two different things.
A display may operate at 144Hz while still exhibiting visible trails behind moving objects if its pixels transition slowly.
A simple way to visualize this is to animate an object across a contrasting background:
const box = document.createElement("div");
Object.assign(box.style, {
width: "80px",
height: "40px",
background: "#ffffff",
position: "fixed",
top: "45%",
left: "0"
});
document.body.style.background = "#333333";
document.body.appendChild(box);
let start;
function animate(timestamp) {
if (start === undefined) start = timestamp;
const elapsed = (timestamp - start) / 1000;
const speed = 600;
const distance = window.innerWidth + 80;
const x = (elapsed * speed) % distance - 80;
box.style.transform = `translateX(${x}px)`;
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
Notice that the animation uses elapsed time rather than moving a fixed distance per frame.
This ensures the object's intended movement speed remains consistent across different refresh rates.
Visual inspection can reveal apparent smearing or trailing, although accurate pixel response-time measurements require specialized equipment.
6. Putting Browser-Based Display Diagnostics Together
These individual techniques can be combined into a more complete display testing workflow.
One existing example is DiagBench, which brings several browser-based display diagnostics into a single interface:
- Fullscreen dead pixel testing
- Refresh rate estimation
- OLED burn-in inspection
- Backlight bleed testing
- Motion ghosting patterns
- Touchscreen testing
- Screen resolution and pixel ratio inspection
Its approach illustrates the distinction between collecting browser-reported metrics and presenting visual patterns for users to interpret.
The website also states that its diagnostic tests run locally in the browser.
7. What Browsers Can and Cannot Measure
Browser APIs are useful, but they are not a replacement for professional display measurement equipment.
| Diagnostic | Browser capability |
|---|---|
| CSS screen dimensions | Directly available |
| Device pixel ratio | Directly available |
| Refresh rate | Estimated from frame timing |
| Dead pixels | Manual visual inspection |
| Backlight bleed | Manual visual inspection |
| OLED burn-in | Manual visual inspection |
| Pixel response time | Qualitative visual assessment |
| Color accuracy | Requires external measurement hardware for accurate results |
This distinction is important when designing hardware diagnostic applications for the web.
A good diagnostic tool should communicate uncertainty rather than present estimated values as definitive hardware measurements.
Final Thoughts
Modern web APIs make it possible to build useful hardware diagnostic tools without native applications.
By combining the Screen API, Fullscreen API, animation frame timing, and simple rendering techniques, developers can create practical tools for investigating display behavior.
The most interesting engineering challenge is not necessarily collecting more data. It's understanding which parts of the system the browser can actually observe.
The next time an animation feels slow or a canvas looks blurry, consider investigating the display environment before rewriting your rendering code.
Further reading:
Have you ever encountered a display-related issue that initially looked like a frontend performance bug?
I'd be interested to hear how you diagnosed it.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.