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

webrtc-ip

v5.0.1

Published

🌐 Enhanced IP address querying with WebRTC

Readme

webrtc-ip

Fast browser public-IP lookup using WebRTC ICE candidates and a STUN server.

import { getIP, prefetchIP } from "webrtc-ip";

void prefetchIP().catch(() => undefined); // start as early as possible

const ip = await getIP();

webrtc-ip is a browser/client-side library. It requires RTCPeerConnection, so it does not run during SSR or in plain Node.js. In unsupported environments, v5 rejects with a typed WebRTCIPError instead of returning an empty string.

Installation

npm install webrtc-ip
bun add webrtc-ip

Usage

Basic

import { getIP } from "webrtc-ip";

try {
  const ip = await getIP();
  console.log(ip);
} catch (error) {
  console.error("Could not resolve IP", error);
}

Next.js / React

Use it from a client component only:

"use client";

import { useEffect, useState } from "react";
import { getIP, prefetchIP } from "webrtc-ip";

void prefetchIP().catch(() => undefined);

export default function Home() {
  const [ip, setIp] = useState<string | null>(null);

  useEffect(() => {
    getIP()
      .then(setIp)
      .catch(() => setIp(null));
  }, []);

  return <p>{ip ?? "Resolving…"}</p>;
}

Options

const ip = await getIP({
  stun: [
    "stun:stun.l.google.com:19302",
    "stun:stun1.l.google.com:19302"
  ],
  timeout: 3000,
  cache: true,
  cacheTtl: 60_000
});

| Option | Default | Description | | --- | --- | --- | | stun | "stun:stun.l.google.com:19302" | STUN URL or URL array. Pass [] with includeLocal: true for local-only candidates. | | timeout | 3000 | Maximum time to wait for ICE candidates, in ms. | | cache | true | Reuse an in-flight/completed lookup for matching options. | | cacheTtl | Infinity | How long completed cached lookups remain fresh, in ms. | | includeLocal | false | Include host/local candidates. Modern browsers may expose mDNS names instead of private IPs. | | signal | undefined | AbortSignal for cancellation. |

Rich result

import { getIPInfo } from "webrtc-ip";

const info = await getIPInfo();

console.log(info.ip);        // "203.0.113.42"
console.log(info.type);      // "srflx", "host", "relay", ...
console.log(info.elapsedMs); // lookup duration, not cached-read time

Safe nullable helper

import { getIPOrNull } from "webrtc-ip";

const ip = await getIPOrNull(); // string | null

Cancellation

const controller = new AbortController();

const promise = getIP({ signal: controller.signal, timeout: 5000 });
controller.abort();

await promise; // rejects with WebRTCIPError code "ABORTED"

API

getIP(options?: string | string[] | GetIPOptions): Promise<string>
getIPInfo(options?: string | string[] | GetIPOptions): Promise<GetIPInfoResult>
getIPOrNull(options?: string | string[] | GetIPOptions): Promise<string | null>
prefetchIP(options?: string | string[] | GetIPOptions): Promise<string>
clearIPCache(): void
isSupported(): boolean
isWebRTCIPError(error: unknown): error is WebRTCIPError

Errors

Failures reject with WebRTCIPError:

import { getIP, isWebRTCIPError } from "webrtc-ip";

try {
  await getIP();
} catch (error) {
  if (isWebRTCIPError(error)) {
    console.log(error.code);
  }
}

Error codes:

  • UNSUPPORTEDRTCPeerConnection is unavailable, such as SSR/Node.js.
  • TIMEOUT — no accepted candidate arrived before timeout.
  • NO_PUBLIC_CANDIDATE — ICE completed without a public/server-reflexive candidate.
  • WEBRTC_BLOCKED — browser policy, permissions, or networking blocked WebRTC setup.
  • INVALID_STUN_URL — a STUN URL is malformed.
  • INVALID_OPTIONStimeout or cacheTtl is invalid.
  • ABORTED — the supplied AbortSignal was aborted.

Notes

  • prefetchIP() starts the same cached lookup that getIP() reads later. This is what makes later calls fast.
  • If you fire-and-forget prefetchIP(), attach a .catch() handler because unsupported or blocked environments reject.
  • WebRTC/STUN still performs a network round trip and can fail on restrictive networks, VPNs, hardened browsers, or when WebRTC/UDP is disabled.
  • Local candidates may be masked as .local mDNS names by modern browsers.

Migration from v4 to v5

  • Unsupported environments now reject with WebRTCIPError code UNSUPPORTED instead of resolving "".
  • Package exports now provide both CommonJS and ESM entry points.
  • New APIs: isSupported, getIPInfo, getIPOrNull, isWebRTCIPError, cacheTtl, and AbortSignal support.

Authors

The author of webrtc-ip is Joey Malvinni.

List of all contributors

License

Apache 2.0