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

metro-bridge

v0.1.2

Published

CDP/Metro bridge for React Native: target discovery, WebSocket session, multiplexer, DevTools launcher, and app-side SDK

Readme

metro-bridge

CDP/Metro bridge for React Native development tooling. Provides target discovery, a WebSocket CDP session, a proxy multiplexer, a high-level bridge API, DevTools launcher, and an optional app-side client SDK.

Used by metro-mcp.

Installation

npm install metro-bridge
# or
bun add metro-bridge

ws is the only required dependency. chrome-launcher and chromium-edge-launcher are optional (needed only for openDevTools()).

Usage

MetroBridge — high-level API

The simplest way to connect to a running React Native app:

import { MetroBridge } from 'metro-bridge'

// Connect (throws if Metro is not running)
const bridge = await MetroBridge.connect(8081)

// Or connect optionally — returns null if Metro is unavailable
const bridge = await MetroBridge.tryConnect(8081)
if (!bridge) {
  console.log('Metro not running, skipping bridge features')
}

// Evaluate JavaScript in the app's Hermes context
const count = await bridge.evaluate<number>('globalThis.__itemCount')

// Wait for React Native's InteractionManager to report idle
await bridge.waitForIdle(5000)

// Capture console output
const unsub = bridge.onConsole((type, args) => {
  console.log(`[app:${type}]`, ...args)
})
unsub() // stop listening

// Mock network requests (JS-layer fetch patch)
await bridge.mockRequest(/api\.example\.com\/users/, {
  status: 200,
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify([{ id: 1, name: 'Alice' }]),
})
await bridge.clearMocks()

// Access the underlying CDPSession for advanced use
const session = bridge.cdpSession

await bridge.close()

CDPSession — low-level CDP connection

import { CDPSession, MetroDiscovery } from 'metro-bridge'

const discovery = new MetroDiscovery(8081)
const targets = await discovery.discover()
const session = await CDPSession.connect(targets[0])

// Send CDP commands
const result = await session.send('Runtime.evaluate', {
  expression: '1 + 1',
  returnByValue: true,
})

// Listen for CDP events
session.on('Runtime.consoleAPICalled', (params) => {
  console.log(params)
})

await session.close()

MetroDiscovery — target discovery

import { MetroDiscovery, fetchTargets, selectBestTarget, scanMetroPorts } from 'metro-bridge'

// Class API
const discovery = new MetroDiscovery(8081)
const targets = await discovery.discover()
const session = await discovery.attach() // attaches to best target
const running = await discovery.isMetroRunning()

// Standalone functions
const targets = await fetchTargets('127.0.0.1', 8081)
const best = selectBestTarget(targets) // prefers Bridgeless > Hermes > standard
const servers = await scanMetroPorts('127.0.0.1') // scans common ports

CDPMultiplexer — share one Hermes connection

Allows Chrome DevTools and your tooling to share a single Hermes debugger connection:

import { CDPSession, MetroDiscovery, CDPMultiplexer, openDevTools } from 'metro-bridge'

const discovery = new MetroDiscovery(8081)
const session = await discovery.attach()

// Start the multiplexer — accepts external WebSocket clients
const multiplexer = new CDPMultiplexer(session, {
  // Domains that your code needs and should never be disabled by external clients
  protectedDomains: ['Runtime', 'Network'],
})
const port = await multiplexer.start()

// Open Chrome DevTools pointed at the multiplexer
const frontendUrl = `http://localhost:8081/debugger-frontend/rn_fusebox.html?ws=127.0.0.1:${port}`
await openDevTools(frontendUrl)

// Your code can still use the session directly
await session.send('Runtime.evaluate', { expression: 'Date.now()', returnByValue: true })

await multiplexer.stop()

openDevTools

import { openDevTools } from 'metro-bridge'

const { opened, url } = await openDevTools('http://localhost:8081/debugger-frontend/rn_fusebox.html?ws=...')
if (!opened) {
  console.log('Open this URL in Chrome:', url)
}

Client SDK

The metro-bridge/client entry provides an optional app-side SDK. Import it inside your React Native app (dev mode only) to expose state and events to your server-side tooling via Runtime.evaluate.

import { MetroBridgeClient } from 'metro-bridge/client'

if (__DEV__) {
  const client = new MetroBridgeClient()

  // Register custom commands callable from the server
  client.registerCommand('resetState', async ({ userId }) => {
    await store.dispatch(resetUser(userId))
    return { ok: true }
  })

  // Capture Redux actions
  client.useReduxMiddleware(store)
  // Then add the middleware to your store:
  // configureStore({ middleware: (getDefault) => getDefault().concat(store.__metroBridgeMiddleware) })

  // Track React Navigation state changes
  client.useNavigationTracking(navigationRef)

  // Track lifecycle events (foreground/background/deep links)
  client.trackLifecycle()

  // Structured logging
  client.log('auth', { event: 'login', userId: '123' })

  // Subscribe arbitrary state (Zustand, MobX, etc.)
  client.subscribeState('cart', () => cartStore.getState())

  // Performance marks
  client.mark('screen-start')
  client.measure('screen-load', 'screen-start', 'screen-ready')
}

React Profiler integration

import { Profiler } from 'react'
import { trackRender } from 'metro-bridge/client'

<Profiler id="ProductList" onRender={trackRender}>
  <ProductList />
</Profiler>

Render records are stored on globalThis.__METRO_BRIDGE__.renders.

Tree-shakeable imports

All pieces of the client SDK can be imported individually:

import {
  registerCommand,
  createReduxMiddleware,
  createNavigationTracking,
  LifecycleTracker,
  StructuredLogger,
  StateSubscriptionManager,
  PerformanceTracker,
  trackRender,
  ClientBuffer,
} from 'metro-bridge/client'

License

MIT