@flareapp/js

中文文档
2.13.0发布于 2026/09/17MITTypeScriptESM + CJS近 30 天下载 6.1万

JavaScript client for flareapp.io

原始使用文档
文档目录9 节
  1. Installation
  2. Quick start
  3. Identifying users
  4. Cookie consent and GDPR
  5. Logging
  6. What happens when someone leaves the page
  7. Documentation
  8. Deprecations
  9. License

@flareapp/js

The core JavaScript/TypeScript client for Flare error tracking and logging. Captures frontend errors, parses stack traces, collects browser context, sends structured logs, and reports everything to the Flare backend.

Installation

npm install @flareapp/js

Quick start

import { flare } from '@flareapp/js';

flare.light('YOUR_FLARE_API_KEY');

That is all you need. The client automatically listens for uncaught exceptions and unhandled promise rejections, collects browser context, and sends error reports to Flare.

Identifying users

Attach the logged-in user to reports so you can see who was affected:

import { flare } from '@flareapp/js';

flare.setUser({
    id: 123,
    email: '[email protected]',
    fullName: 'Jane Doe',
});

Recognised fields: id (→ user.id), email (→ user.email), fullName (→ user.full_name), ipAddress (→ client.address). Any extra keys are collected under user.attributes. Pass null to clear the user on logout: flare.setUser(null).

The client can run behind a consent tool. When consent is off, it sends nothing. Before consent, it does not even assemble a report.

The switch is one method:

flare.setConsent(true); // allow sending
flare.setConsent(false); // stop sending, and drop anything captured earlier

Recommended flow: do not call flare.light(key) until consent is granted. With no key, nothing sends, so this covers the moment before your consent code runs. Use setConsent for withdrawal and re-grant, because once the key is set it is the only clean off switch.

import { flare } from '@flareapp/js';

// Cookiebot example. OneTrust exposes OptanonWrapper; the idea is the same.
window.addEventListener('CookiebotOnAccept', () => {
    flare.light('your-project-key'); // first grant: start the client
    flare.setConsent(true); // and allow sending
});

window.addEventListener('CookiebotOnDecline', () => {
    flare.setConsent(false); // withdrawal: stop all sends, drop buffers
});

If you set the key at boot instead of waiting, start with consent off, then turn it on when the user accepts:

import { flare } from '@flareapp/js';

flare.configure({ hasConsent: false }); // start off, before anything can send
flare.light('your-project-key');

window.addEventListener('CookiebotOnAccept', () => flare.setConsent(true));
window.addEventListener('CookiebotOnDecline', () => flare.setConsent(false));

Put configure({ hasConsent: false }) first, right after the import, so the gate is off before an early uncaught error can assemble a report.

Consent defaults to on, so setups without a consent tool are unchanged. setConsent(false) stops data leaving the browser. It does not remove the fetch and XHR patches that tracing and breadcrumbs install, because those only read in memory and never send on their own. To remove those too, call flare.configure({ enableTracing: false, enableBreadcrumbs: false }).

Logging

Beyond errors, the client can send structured logs. Logs are opt-in: enable them with enableLogs, then call any of the eight syslog levels (debug, info, notice, warning, error, critical, alert, emergency).

flare.configure({ enableLogs: true });

flare.logger.info('Checkout started', { cartId: cart.id, total: cart.total });

Logs are buffered and batched, and flushed when the tab is hidden so buffered logs survive a page unload. The optional second argument is structured, searchable attributes.

What happens when someone leaves the page

Logs and spans are batched, so there's usually something unsent when a visitor leaves. The client flushes it when the tab is hidden or the page closes.

Browsers cap what you can send at that moment: roughly 64KB across every request still in flight. The client stays under 60KB, and logs and spans share that budget.

Switching tabs is safe. Hiding a tab triggers the same flush, and whatever didn't fit goes out when the visitor comes back.

If nothing fits, the batch is still sent, as a normal request instead of a keepalive one. That usually lands, but it can be cancelled if the page closes right then.

You'll only hit the limit on pages that produce a lot of telemetry before the visitor leaves. Log less on those pages rather than raising the limits.

Documentation

Full documentation on configuration, hooks, context, breadcrumbs, solution providers, and more is available at flareapp.io/docs/javascript/general/installation.

Deprecations

redactFullPath is now a deprecated alias for redactUrlQuery. Both names are still exported and continue to work; prefer redactUrlQuery in new code.

License

The MIT License (MIT). Please see License File for more information.

版本与发布记录

@flareapp/js 共发布 31 个版本,首次发布于 2024/01/25;过去 12 个月发布了 21 个版本。

版本发布日期距今
2.13.0latest2026/09/171 个月前
2.12.22026/09/142 个月前
2.12.12026/09/112 个月前
2.12.02026/09/022 个月前
2.11.02026/08/272 个月前
2.10.02026/08/262 个月前

关于 @flareapp/js 的常见问题

@flareapp/js 是什么?

JavaScript client for flareapp.io

如何安装 @flareapp/js?

在项目目录运行 npm install @flareapp/js,或使用 pnpm add / yarn add / bun add。

@flareapp/js 支持 TypeScript 吗?

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

@flareapp/js 支持 ESM 还是 CommonJS?

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

@flareapp/js 可以商用吗?

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

@flareapp/js 的下载量有多少?

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

@flareapp/js 还在维护吗?

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