npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

detect-electron

v0.1.0

Published

Tiny, SSR-safe utility to detect whether code is running inside Electron.

Readme

detect-electron

Tiny, SSR-safe utility to detect whether code is running inside Electron.

  • Zero runtime dependencies
  • Strict TypeScript with first-class types
  • Safe to import in SSR (Next.js, Remix, Vite, Astro, SvelteKit)
  • Tree-shakeable ESM + CJS bundles (~1.3 KB ESM)
  • Detects renderer, main process, and userAgent fallback

Installation

npm i detect-electron

Usage

import { isElectron } from 'detect-electron';

if (isElectron()) {
  // running inside Electron (renderer or main)
}

You can also import the focused helpers when you need a specific signal:

import {
  isElectronMain,
  isElectronRenderer,
  isElectronUserAgent,
} from 'detect-electron';

isElectronRenderer(); // true in the renderer process
isElectronMain(); // true in the main process
isElectronUserAgent(); // true when navigator.userAgent contains `Electron`

API

isElectron(options?): boolean

Returns true when the current runtime is Electron. The check combines three independent signals, evaluated in order:

  1. Renderer process — window.process.versions.electron
  2. Main process — process.versions.electron
  3. User agent fallback — navigator.userAgent contains Electron

options.environment lets you inject globals for testing or unusual runtimes.

import { isElectron } from 'detect-electron';

isElectron({
  environment: {
    process: { versions: { node: '20.0.0', electron: '28.0.0' } },
  },
}); // → true

isElectronRenderer(env?): boolean

True when the resolved window exposes a renderer-side process.versions.electron shim.

isElectronMain(env?): boolean

True when the resolved process.versions.electron is a non-empty string.

isElectronUserAgent(env?): boolean

True when navigator.userAgent contains the substring Electron. Useful as a fallback when the renderer's process shim has been disabled (nodeIntegration: false without a preload bridge).

Types

interface IsElectronOptions {
  readonly environment?: ElectronDetectionEnvironment;
}

interface ElectronDetectionEnvironment {
  readonly window?: { readonly process?: unknown } | undefined;
  readonly process?:
    | {
        readonly versions?: Readonly<Record<string, string | undefined>>;
      }
    | undefined;
  readonly navigator?: { readonly userAgent?: string } | undefined;
}

SSR safety

The module performs no global access at import time. Every helper reads globalThis lazily and gates each lookup, so it is safe to use in:

  • Next.js (App Router and Pages Router)
  • Remix
  • SvelteKit
  • Astro
  • Vite SSR
  • Any worker / edge runtime

Testing your own code

Because every public function accepts an optional environment argument, you can drive deterministic tests without polluting real globals:

import { isElectron } from 'detect-electron';
import { describe, expect, it } from 'vitest';

describe('my feature', () => {
  it('takes the Electron path', () => {
    expect(
      isElectron({
        environment: {
          window: { process: { versions: { electron: '28.0.0' } } },
        },
      }),
    ).toBe(true);
  });

  it('takes the browser path', () => {
    expect(isElectron({ environment: { window: {} } })).toBe(false);
  });
});

License

© 2026 Breno Polanski

Licensed under MIT