New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

vite-plugin-fps-meter

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-fps-meter

vite-plugin-fps-meter is a tiny Vite plugin that overlays a live FPS / ms badge (with p95/p99 and Long Task %) on your app. It can auto-inject in dev or build, toggles via URL/localStorage, adapts to Vite's error overlay, and exposes a simple runtime API.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

vite-plugin-fps-meter

vite-plugin-fps-meter is a tiny Vite plugin that overlays a live FPS / ms badge (with p95/p99 and Long Task %) on your app. It can auto-inject in dev or build, toggles via URL/localStorage, adapts to Vite's error overlay, and exposes a simple runtime API.

npm GitHub package version NPM Downloads


Install

# yarn
yarn add -D vite-plugin-fps-meter

# pnpm
pnpm add -D vite-plugin-fps-meter

# npm
npm i -D vite-plugin-fps-meter

Quick Start

// vite.config.ts
import { defineConfig } from 'vite';
import fpsMeter from 'vite-plugin-fps-meter';

export default defineConfig({
  plugins: [
    fpsMeter({
      // Show badge only in dev by default ("dev" | "build" | boolean)
      enabled: 'dev',

      // Optional fine-tuning (defaults shown below in Options)
      position: 'tl',
      maxDisplayFps: 240,
    }),
  ],
});

How it looks / Works

  • Click the badge to cycle: FPS → ms → p95 → p99.
  • Long Task % shows how much time (in the last update window) was spent in Long Tasks (if supported by the browser).
  • The badge will automatically move to the bottom if Vite's error overlay appears while your preferred position is top.
  • A tiny in-memory window is used to compute percentiles.

Options

FieldTypeDefaultDescription
enabledboolean | 'dev' | 'build''dev'Controls when the runtime is injected and started. 'dev' = Vite serve, 'build' = during build preview/runtime, true/false to force on/off.
updateIntervalMsnumber250UI update interval (ms).
smoothingTauMsnumber300EMA smoothing time constant (ms).
skipFrameThresholdMsnumber400Skip frames with dt above this threshold (e.g., tab switches) to avoid skewing EMA.
pauseOnHiddenbooleantruePause meter when document.hidden is true.
maxDisplayFpsnumber240Cap displayed FPS.
position'tl' | 'tr' | 'bl' | 'br''tl'Badge position: top/bottom & left/right.
zIndexnumber2147483647CSS z-index of the badge.
storageKeystring'vite:fps-meter'LocalStorage key for persisted toggle.
showInIframebooleantrueIf false, the meter won't render inside iframes.
percentileWindowSizenumber300Number of recent frame durations used to compute p95/p99.

Runtime controls

  • URL param: ?fps=1 to force-enable, ?fps=0 to force-disable on first load.
  • Persistence: state is saved in localStorage['vite:fps-meter'] (customizable via storageKey).
  • Global API (injected):
// Toggle at runtime
window.__fpsMeter?.setEnabled(false);
window.__fpsMeter?.setEnabled(true);

// Read current state
const on = window.__fpsMeter?.isEnabled();

Programmatic init (advanced)

By default, the plugin auto-injects and auto-starts. If you need a custom instance, you can import the virtual client and mount manually:

// Somewhere in your app (advanced usage)
import initFpsMeter from 'virtual:fps-meter-client';

const dispose = initFpsMeter({ position: 'br' });
// ...later
dispose();

Note: manual init will create another badge in addition to the auto-injected one. Prefer the global API above unless you have a specific reason to manage instances yourself.


Notes on metrics

  • FPS and ms are derived from a smoothed EMA of frame durations.
  • p95/p99 are computed over a small sliding window of recent frames to avoid heavy allocations.
  • Long Task % uses PerformanceObserver with { type: 'longtask', buffered: true }. If unsupported, it's silently disabled.

Compatibility

  • Vite: peer dependency ^5 | ^6 | ^7.
  • Node: >=18.
  • Works in iframes unless showInIframe: false is set.

License

MIT

Keywords

vite

FAQs

Package last updated on 07 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts