Urgent.News

What's breaking now, across thousands of outlets.

Tech

How I Built a Real-Time Display Refresh Rate Tester Using Astro.js & requestAnimationFrame

As developers, gamers, and tech enthusiasts, we often invest in high refresh rate monitors (120Hz, 144Hz, or even 240Hz). But here is a common problem: just because your operating system settings say 144Hz doesn't mean your browser is actually rendering at that speed. Sometimes, a faulty HDMI/DP cable, incorrect GPU settings, or browser hardware acceleration issues can silently cap your frame…

In the realm of developers, gamers, and tech enthusiasts, a prevalent issue arises: despite operating system settings indicating a high refresh rate such as 144Hz, the actual browser performance may fail to match that speed. Various factors, including faulty HDMI/DP cables, incorrect GPU settings, or browser hardware acceleration problems, can quietly throttle the frame rate down to 60Hz.

Seeking a swift, installation-free method to verify genuine screen refresh rate right within the browser, the author decided to create their own solution. Hence, they introduce the Refresh Rate Tester tool.

With the objective of constructing an exceptionally fast and lightweight tool, the author chose the following technology stack: Astro.js for an optimized, static foundation that avoids constant JavaScript execution, Tailwind CSS for responsive, clean styling adaptable to both desktop and mobile devices, and Vanilla JavaScript for the core functionality.

At its core, the tool relies on the browser's native requestAnimationFrame API. This method eschews the attempt to read system-level hardware settings, which browsers generally cannot access due to security concerns. Instead, it quantifies the time interval between consecutive screen repaints. The following code snippet illustrates the logic:

```javascript

let frameCount = 0;

let lastTime = performance.now();

let currentHz = 0;

function calculateRefreshRate() {

let now = performance.now();

frameCount++;

if (now - lastTime >= 1000) {

currentHz = frameCount;

console.log(`Current Refresh Rate: ${currentHz} Hz`);

frameCount = 0;

lastTime = now;

}

requestAnimationFrame(calculateRefreshRate);

}

requestAnimationFrame(calculateRefreshRate);

```

By documenting the number of frames the browser manages to render in a single second, the tool accurately determines the screen's refresh rate (measured in Hertz). All processing occurs on the client side, eliminating any dependency on server latency and ensuring precise results. Users can instantly assess their display's refresh rate through the following link: https://refreshrate.net.

The author invites feedback regarding the UI design, performance, and any proposed features, such as motion blur or frame skipping tests. They encourage readers to share their findings, specifically noting the Hz their current screen operates at.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Tuesday 17 November →