@cjser/get-windows

中文文档
10.0.0-cjser.2发布于 2026/11/01MITTypeScriptESM + CJS零依赖

Get metadata about the active window and open windows (title, id, bounds, owner, URL, etc)

原始使用文档
文档目录15 节
  1. Install
  2. Usage
  3. API
  4. activeWindow(options?)
  5. activeWindowSync(options?)
  6. Result
  7. openWindows()
  8. openWindowsSync()
  9. OS support
  10. Linux support
  11. Electron usage
  12. Users
  13. Related
  14. Development
  15. cjser

get-windows

Get metadata about the active window and open windows (title, id, bounds, owner, URL, etc)

Works on macOS 10.14+, Linux (note), and Windows 7+.

Install

npm install get-windows

This is an ESM package which requires you to use ESM

Usage

import {activeWindow} from 'get-windows';

console.log(await activeWindow(options));
/*
{
    title: 'Unicorns - Google Search',
    id: 5762,
    bounds: {
        x: 0,
        y: 0,
        height: 900,
        width: 1440
    },
    owner: {
        name: 'Google Chrome',
        processId: 310,
        bundleId: 'com.google.Chrome',
        path: '/Applications/Google Chrome.app'
    },
    url: 'https://sindresorhus.com/unicorn',
    memoryUsage: 11015432
}
*/

API

activeWindow(options?)

Get metadata about the active window.

options

Type: object

accessibilityPermission (macOS only)

Type: boolean
Default: true

Enable the accessibility permission check. Setting this to false will prevent the accessibility permission prompt on macOS versions 10.15 and newer. The url property won't be retrieved.

screenRecordingPermission (macOS only)

Type: boolean
Default: true

Enable the screen recording permission check. Setting this to false will prevent the screen recording permission prompt on macOS versions 10.15 and newer. The title property in the result will always be set to an empty string.

activeWindowSync(options?)

Get metadata about the active window synchronously.

Result

Returns a Promise<object> with the result, or Promise<undefined> if there is no active window or if the information is not available.

  • platform (string) - 'macos' | 'linux' | 'windows'
  • title (string) - Window title
  • id (number) - Window identifier
  • bounds (Object) - Window position and size
    • x (number)
    • y (number)
    • width (number)
    • height (number)
  • contentBounds (Object) - Window content position and size, which excludes the title bar, menu bar, and frame (Windows only)
    • x (number)
    • y (number)
    • width (number)
    • height (number)
  • owner (Object) - App that owns the window
    • name (string) - Name of the app
    • processId (number) - Process identifier
    • bundleId (string) - Bundle identifier (macOS only)
    • path (string) - Path to the app
  • url (string?) - URL of the active browser tab if the active window is a supported browser (macOS only)
    • Supported browsers: Safari (includes Technology Preview), Chrome (includes Beta, Dev, and Canary), Edge (includes Beta, Dev, and Canary), Brave (includes Beta and Nightly), Mighty, Ghost Browser, Wavebox, Sidekick, Opera (includes Beta, Developer, and GX), or Vivaldi
  • memoryUsage (number) - Memory usage by the window owner process

openWindows()

Get metadata about all open windows.

Windows are returned in order from front to back.

Returns Promise<Result[]>.

The array is empty if the window list cannot be read.

openWindowsSync()

Get metadata about all open windows synchronously.

Windows are returned in order from front to back.

Returns Result[].

The array is empty if the window list cannot be read.

OS support

It works on macOS 10.14+, Linux, and Windows 7+.

Note: On Windows, there isn't a clear notion of a "Window ID". Instead it returns the memory address of the window "handle" in the id property. That "handle" is unique per window, so it can be used to identify them. Read more…

Linux support

Wayland is not supported. For security reasons, Wayland does not provide a way to identify the active window. Read more…

Electron usage

If you use this package in an Electron app that is sandboxed and you want to get the .url property, you need to add the proper entitlements and usage description.

Users

Development

To bypass the gyp build:

npm install --ignore-scripts
  • Debug logging: Set DEBUG_GET_WINDOWS=1 to log Linux window enumeration errors and summary counts to the console.

cjser

This package is a CommonJS-compatible build generated by cjser for projects that still need require() support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build. Original repository: https://github.com/sindresorhus/get-windows

版本与发布记录

@cjser/get-windows 共发布 2 个版本,首次发布于 2026/05/07;过去 12 个月发布了 2 个版本。

版本发布日期距今
10.0.0-cjser.2latest2026/11/012 天前
9.3.0-cjser.22026/05/075 个月前

关于 @cjser/get-windows 的常见问题

@cjser/get-windows 是什么?

获取有关活动窗口和打开窗口的元数据(标题、id、边界、所有者、URL等)

如何安装 @cjser/get-windows?

在项目目录运行 npm install @cjser/get-windows,或使用 pnpm add / yarn add / bun add。

@cjser/get-windows 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cjser/get-windows 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cjser/get-windows 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cjser/get-windows 可以商用吗?

@cjser/get-windows 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cjser/get-windows 还在维护吗?

最新版本 10.0.0-cjser.2 发布于 2026/11/01(2 天前);至今共发布 2 个版本,其中过去 12 个月发布了 2 个;首次发布于 2026/05/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。