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

@ausm/device-macos-viewport-manager

v0.1.0

Published

Window viewport state monitoring for macOS — tracks window lifecycle events via a Swift helper subprocess

Readme

@ausm/device-macos-viewport-manager

Tracks every user-visible window on macOS and reports when windows appear, gain or lose focus, vanish, are renamed, or move/resize. It also reports Mission Control Space switches. A Swift helper (build/viewport-helper) does the work and streams JSON lines to this Node wrapper.

macOS 12+, Node 18+. Universal binary (arm64 + x86_64).

Permissions

| Permission | Without it | | --- | --- | | Screen Recording | macOS hides other apps' window titles. Untitled windows are skipped, so most windows are not reported. | | Accessibility | Focus is still detected by polling (≤ 16 ms latency), but instant AX focus changes and documentPath are unavailable. |

macOS grants both to the responsible app (your terminal or Electron app). The helper never prompts. It reports the current state in a permission event at startup and again whenever it changes, so you can guide the user. Accessibility granted while running takes effect immediately. A Screen Recording grant may only take effect after the responsible app is relaunched (a macOS limitation).

Usage

import { createViewportMonitor } from '@ausm/device-macos-viewport-manager';

const monitor = createViewportMonitor();
monitor.on('permission', (p) => {
  if (!p.screenRecordingGranted) console.warn('Grant Screen Recording to see window titles');
});
monitor.on('window-focused', (e) => console.log('focus', e.bundleId, e.windowId));
monitor.on('space-changed', () => console.log('space switched'));
monitor.on('error', (err) => console.error(err));

monitor.start({ debug: false, autoRestart: true }); // returns false if the helper is missing / not macOS
// ...
monitor.cleanup(); // stop + remove listeners

start(config):

  • debug (default false): log events, including window titles.
  • autoRestart (default true): respawn a crashed helper with exponential backoff (1 s … 30 s, 5 attempts; the counter resets after 60 s of healthy running). If it gives up, it emits error and then status: 'stopped'.

If there is no error listener, errors are logged with console.warn instead of throwing.

Events

| Event | Payload | | --- | --- | | window-event | Every window event below | | window-opened | A window became visible: created, un-minimized, app unhidden, or Space switched to it | | window-closed | A window disappeared: closed, minimized, app hidden/quit, or left the current Space | | window-focused / window-unfocused | Focus moved. The unfocus of a closing window comes before its close. | | bounds-changed | Position or size changed (oldBounds set). Dropped when several windows move in the same tick (Space swipes, display reconfiguration). | | title-changed | Title changed (oldTitle set) | | space-changed | { type: 'space-changed', timestamp } | | permission | { accessibilityTrusted, screenRecordingGranted } | | status | 'started' \| 'stopped' | | error | Error |

WindowEvent fields: type, windowId (CGWindowID), title, ownerName, bundleId, pid, bounds {x, y, width, height}, displayId, documentPath? (file:// URL from AXDocument), oldTitle?, oldBounds?, timestamp (ms, set on receipt in Node).

  • Coordinates are global CoreGraphics points. The origin is the top-left of the main display, y grows downward, and displays left of or above the main display have negative coordinates.
  • displayId is the CGDirectDisplayID with the largest overlap with the window. The display list is re-read on every tick, so hot-plugging is handled.
  • Tracked windows are layer-0, on-screen, at least 100×100 pt, titled, and not owned by system UI (Dock, Control Center, Spotlight, …). Full-screen apps are tracked like any other window on their Space.

Helper protocol (stdout, one JSON object per line)

  1. {"type":"ready","accessibilityTrusted":bool,"screenRecordingGranted":bool, ...zeroed window fields}
  2. Window events, using the field names above (no timestamp).
  3. {"type":"space-changed","timestamp":ms}
  4. {"type":"permission","accessibilityTrusted":bool,"screenRecordingGranted":bool} on change.

stderr carries diagnostics only. The helper never writes window titles or paths there. The helper exits on SIGTERM/SIGINT, on stdin EOF (the wrapper keeps stdin open as a pipe), or when its parent process dies.

Performance notes

The helper polls CGWindowListCopyWindowInfo at about 60 Hz. AXDocument lookups are cached per window and title (including misses). Every AX call has a 250 ms timeout so a hung app cannot stall the monitor.

Build

npm run build         # universal Swift helper → build/viewport-helper (ad-hoc signed) + TS → dist/
npm run build:swift   # helper only; set SIGN_IDENTITY to sign with a real identity
npm run typecheck
npm run test:swift    # XCTest: diffing, display assignment, JSON shape; no permissions needed
node test-live.js     # manual live viewer (prints window titles)

The universal build needs a full Xcode installation.