@haatlabs-core/extension-kit

中文文档
0.18.5发布于 2026/11/14Apache-2.0TypeScriptES Module近 30 天下载 4737

The browser side of an extension's panel: the active tab, page reads, downloads, sign-in keys.

原始使用文档

@haatlabs-core/extension-kit

The browser side of an extension's panel (Manifest V3): the PanelEnv of @haatlabs-core/extension-ui for a Chrome or Edge side panel, the service worker's setup, and the key an app's own connect page hands the extension.

Install

pnpm add @haatlabs-core/extension-kit

Use

  • createChromePanelEnv(): the active tab (once the person clicked the icon there, or allowed every site), tab changes in the panel's own window, downloads (a file made in parts is saved as one), JSON read from inside the page as the page would, and the page's scripts and globals.
  • openSidePanelOnIconClick(), in the service worker: the toolbar icon opens the side panel.
  • Sign-in through the app's own connect page: startConnect(webOrigin) opens <webOrigin>/connect/extension?extension=<id>; listenForConnections({ <app>: <webOrigin> }) in the service worker keeps the key that page sends (<app>.connected), only from that origin; createAuthStore(app) reads, keeps and forgets it in local storage (never synced).

For an extension of an app with its own backend (not built on the platform):

  • fillFields(tabId, [{ selector, value }]) fills a page's form in the page's own world, so React and Vue forms keep the values (a <select> by its value or its text), and returns { filled, missing }: show what was missing, never skip it. copyText(text) copies.
  • SiteAdapter: one site's form as data (matches as Chrome match patterns, the anchor field, and fields(data, page)); matchAdapter(url, adapters) picks the page's.
  • installFillButton({ adapters, label, onFill }), in a content script: a button beside the form's first field once it appears.
  • startOAuthPkce({ authorizeUrl, tokenUrl, clientId, scopes }) signs in through chrome.identity with OAuth 2 and PKCE (S256, state checked) and returns { accessToken, refreshToken, expiresAt }; refreshOAuth(grant, tokenUrl, clientId) renews it in its last minute. createAuthStore keeps either kind of grant.

Chrome, Edge, Firefox and Safari from one code base:

  • browserName() (chromium, firefox, safari, from the scheme of the extension's own pages) and extensionApi() (browser where there is one, else chrome). createChromePanelEnv works in each: Firefox and Safari answer chrome.* too.
  • openPanelOnIconClick(), in the background script: Chromium's side panel, Firefox's sidebar; on Safari the panel is the action's popup.
  • manifestFor(browser, base, { geckoId }) writes each browser's manifest from one Chromium base: Firefox gets sidebar_action, a background script and browser_specific_settings; Safari a popup and no identity permission.
  • startOAuthPkce signs in with chrome.identity or browser.identity; on Safari, which has none, through a tab to the app's own page (safariRedirectUri), which hands the answer back with browser.runtime.sendMessage.

The manifest needs the sidePanel, scripting, downloads, storage and activeTab permissions, optional_host_permissions: ["https://*/*"], and the app's web origin in externally_connectable.

The package is for the browser only: its code runs in an extension, through a bundler.

版本与发布记录

@haatlabs-core/extension-kit 共发布 27 个版本,首次发布于 2026/10/23;过去 12 个月发布了 27 个版本。

版本发布日期距今
0.18.5latest2026/11/144 天前
0.18.42026/11/134 天前
0.18.32026/11/134 天前
0.18.22026/11/134 天前
0.18.12026/11/134 天前
0.18.02026/11/134 天前

关于 @haatlabs-core/extension-kit 的常见问题

@haatlabs-core/extension-kit 是什么?

The browser side of an extension's panel: the active tab, page reads, downloads, sign-in keys.

如何安装 @haatlabs-core/extension-kit?

在项目目录运行 npm install @haatlabs-core/extension-kit,或使用 pnpm add / yarn add / bun add。

@haatlabs-core/extension-kit 支持 TypeScript 吗?

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

@haatlabs-core/extension-kit 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@haatlabs-core/extension-kit 需要什么版本的 Node.js?

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

@haatlabs-core/extension-kit 可以商用吗?

@haatlabs-core/extension-kit 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@haatlabs-core/extension-kit 的下载量有多少?

根据 npm 官方下载统计,@haatlabs-core/extension-kit 在 2026/10/17 – 2026/11/15 这 30 天内被下载 4,737 次,日均约 158 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@haatlabs-core/extension-kit 还在维护吗?

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