@hibira-io/push-web

中文文档
1.3.0发布于 2026/11/01MITTypeScriptES Module零依赖构建来源已验证

Web push notifications for Hibira Push: a drop-in client for apps moving from Pusher Beams

原始使用文档
文档目录7 节
  1. Install
  2. Service worker
  3. Use
  4. Ask visitors to turn on notifications
  5. Moving from @hikibi/push-web
  6. Moving from the Beams web SDK
  7. License

@hibira-io/push-web

Web push notifications for Hibira Push. It is the web client for the Beams-compatible push API: an MIT-licensed fork of the Pusher Beams web SDK with the host made configurable, so code written for that SDK keeps working after changing the import.

Works in browsers with standard Web Push: Chrome, Edge, Firefox, Opera and Safari 16.4+ (the Beams SDK did not enable Safari).

Install

npm install @hibira-io/push-web

Or load the script, which defines the global HibiraPush:

<script src="https://cdn.jsdelivr.net/npm/@hibira-io/push-web@1/dist/push-web.min.js"></script>

Service worker

Serve a /service-worker.js at your site root that loads ours:

importScripts('https://cdn.jsdelivr.net/npm/@hibira-io/push-web@1/dist/service-worker.js');
// Only if your app is not on the default cluster:
// self.HibiraPush.endpoint = 'https://ws-tyo.hibira.io';

You can also copy node_modules/@hibira-io/push-web/dist/service-worker.js into your site. To handle notifications yourself, set self.HibiraPush.onNotificationReceived (same arguments as Beams' onNotificationReceived).

Use

import { Client, TokenProvider } from '@hibira-io/push-web';

const push = new Client({
  instanceId: 'YOUR_INSTANCE_ID', // portal: app page → Push notifications
  // endpoint: 'https://ws.hibira.io', // the default
});

await push.start();
await push.addDeviceInterest('news');

// Authenticated users: your backend returns a user token
// (generateToken in the server SDKs).
await push.setUserId('alice', new TokenProvider({ url: '/push/user-token' }));

endpoint is the push API base URL shown on the app page in the portal. endpointOverride is accepted as a synonym.

Ask visitors to turn on notifications

Browsers only let a site show their permission box a few times, and a visitor who clicks "Block" can't be asked again. promptForNotifications shows our own banner first (like the one Gmail shows) and opens the browser's box only after the visitor clicks "Turn on". Once they allow it, the browser is registered, and the interests and user ID you pass are set.

import { promptForNotifications } from '@hibira-io/push-web';

const { outcome } = await promptForNotifications({
  instanceId: 'YOUR_INSTANCE_ID',
  interests: ['orders'],
  siteName: 'Acme Shop',
});
// outcome: 'granted' | 'denied' | 'dismissed' | 'skipped' | 'unsupported' | 'error'

Call it on every page load: it shows nothing to visitors who already allowed notifications (it just makes sure they are registered), to browsers without Web Push, or while a "Not now" is cooling down.

  • "Not now" waits cooldownDays (7) before asking again, and stops after maxAsks (3). resetNotificationPrompt(instanceId) forgets the answers; force: true asks anyway, for a "Turn on notifications" button in your settings.
  • Blocked: showBlockedHelp: true shows how to unblock notifications in the browser instead of nothing.
  • Language: English, 繁體中文, 简体中文, 日本語, 한국어, ไทย and Tiếng Việt, picked from the browser. Set locale, or replace any string with text ({site} is filled with siteName).
  • Look: layout: 'bar' (default, along the top or bottom edge) or 'card' (a corner), position, theme (auto/light/dark), accent, icon, zIndex, delay. The banner sits in a shadow root, so your CSS doesn't affect it and its CSS doesn't leak into your page.
  • client, userId with tokenProvider, onShow and onResult are also accepted; see index.d.ts for every option.

With the CDN script it is HibiraPush.promptForNotifications({...}). Either way, the /service-worker.js above is still needed.

Moving from @hikibi/push-web

Hikibi is now Hibira, and this package moved from @hikibi/push-web to @hibira-io/push-web. The API is the same: change the import and the importScripts URL, and use HibiraPush where you used HikibiPush (the old name is gone since 1.2.0). @hikibi/push-web 1.0.0 stays on npm (deprecated) and gets no new versions.

Moving from the Beams web SDK

Beams web SDK@hibira-io/push-web
import * as PusherPushNotifications from '@pusher/push-notifications-web'import * as HibiraPush from '@hibira-io/push-web'
new PusherPushNotifications.Client({ instanceId })new HibiraPush.Client({ instanceId })
importScripts('https://js.pusher.com/beams/service-worker.js')importScripts('https://cdn.jsdelivr.net/npm/@hibira-io/push-web@1/dist/service-worker.js')
PusherPushNotifications.onNotificationReceived = … in the service workerHibiraPush.onNotificationReceived = …

Everything else (start, interests, setUserId, stop, clearAllState, getRegistrationState and its values) is unchanged. Browsers that were registered with Beams register again on the first start().

License

MIT. Based on the Pusher Beams web SDK, Copyright (c) 2019 Pusher; see LICENSE.

版本与发布记录

@hibira-io/push-web 共发布 5 个版本,首次发布于 2026/10/24;过去 12 个月发布了 5 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.3.0latest2026/11/012 天前
1.2.12026/10/294 天前
1.2.02026/10/259 天前
1.1.02026/10/2410 天前
0.0.0-stage2026/10/2410 天前

关于 @hibira-io/push-web 的常见问题

@hibira-io/push-web 是什么?

Hibira push的Web推送通知:一个从push Beams移动的应用程序的插入式客户端

如何安装 @hibira-io/push-web?

在项目目录运行 npm install @hibira-io/push-web,或使用 pnpm add / yarn add / bun add。

@hibira-io/push-web 支持 TypeScript 吗?

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

@hibira-io/push-web 支持 ESM 还是 CommonJS?

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

@hibira-io/push-web 需要什么版本的 Node.js?

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

@hibira-io/push-web 可以商用吗?

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

@hibira-io/push-web 还在维护吗?

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