# @fastly/performance-observer-polyfill 中文文档

规范地址：https://npmcn.com/package/%40fastly/performance-observer-polyfill/

版本：2\.0\.0
npm 元数据更新时间：2026-08-03T19:11:26.855Z
中文译文更新时间：2026-11-14T11:22:35.637Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40fastly/performance-observer-polyfill
原文对照：https://npmcn.com/package/%40fastly/performance-observer-polyfill/?lang=original
项目主页：https://github.com/fastly/performance-observer-polyfill#readme
源码仓库：https://github.com/fastly/performance-observer-polyfill

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：328 kB，26 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：1 个
- 首次发布：2019-06-13T15:13:27.071Z
- 最新版本发布：2021-02-23T14:56:25.842Z
- 近 30 天下载量：256262（2026-10-15 至 2026-11-13，npm 官方下载统计）
- 已发布版本数：12（近 12 个月 0 个）

## 中文简介

# \* 业绩观察员

[](https://travis-ci.org/fastly/performance-observer-polyfill)

## 安装

```sh
npm install @fastly/performance-observer-polyfill
```

也可以使用：`pnpm add @fastly/performance-observer-polyfill`、`yarn add @fastly/performance-observer-polyfill`、`bun add @fastly/performance-observer-polyfill`

## README

# \* 业绩观察员

 [![Travis](https://img.shields.io/travis/fastly/performance-observer-polyfill/master.svg)](https://travis-ci.org/fastly/performance-observer-polyfill)[![gzip size](https://img.badgesize.io/https://unpkg.com/@fastly/performance-observer-polyfill/polyfill/index.js?compression=gzip)](https://unpkg.com/@fastly/performance-observer-polyfill/polyfill)

这个 [`PerformanceObserver`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserver) 界面是一个 JavaScript API,可用于观测 [时间线](https://www.w3.org/TR/performance-timeline-2/#dfn-performance-timeline) 在记录时,应通知新的业绩计量.

这种多填充允许消费者使用 `PerformanceObserver` 界面在浏览器环境中,它们具有基本的性能时间线支持(I.e. `window.performance.getEntries()`)),但没有观察者支持.

综合填充工作是回到投票时段的投票,并给所有订阅的观察员打电话,请他们提供整套投票结果.

## 快速链接

-   [安装](https://npmcn.com/package/%40fastly/performance-observer-polyfill/#readme-installation)
-   [使用量](https://npmcn.com/package/%40fastly/performance-observer-polyfill/#readme-usage)
-   [发展](https://npmcn.com/package/%40fastly/performance-observer-polyfill/#readme-development)
-   [许可证](https://npmcn.com/package/%40fastly/performance-observer-polyfill/#readme-license)

## 安装

```sh
npm install --save @fastly/performance-observer-polyfill
```

## 用法 :

### 作为一名 [多边填充](https://ponyfill.com/#polyfill)

自动“ 安装” 性能观察器 `window.PerformanceObserver()` 如果检测到性能观察器不支持:

```js
import '@fastly/performance-observer-polyfill/polyfill'

// PerformanceObserver is now available globally!
const observer = new PerformanceObserver((list) => {});
observer.observe({entryTypes: ['resource']});
```

### 用法:作为 [填马](https://github.com/sindresorhus/ponyfill)

用一个模块捆绑器像 [滚动](http://rollupjs.org/) 或者说 [网络软件包](https://webpack.js.org/), (中文(简体) ), 您可以导入 `@fastly/performance-observer-polyfill` 在代码中不修改任何全局 :

```js
// using JS Modules:
import PerformanceObserver from '@fastly/performance-observer-polyfill'

// or using CommonJS:
const PerformanceObserver = require('@fastly/performance-observer-polyfill')

// usage:
const observer = new PerformanceObserver((list) => {});
observer.observe({entryTypes: ['resource']})
```

## 洞穴

由于多填充方式通过回归投票执行绩效观察员界面,通过呼叫恢复投票 `window.performance.getEntries()` 我们仅限于披露时间轴条目类型,这些类型由 `getEntries()`因此,多填充只能用于观察条目类型: `navigation`, (中文(简体) ), `resource` 财务报告和审定财务报表 `mark`。更新条目类型,例如 `paint` 只能通过当地执行绩效观察员进行曝光,因此不能进行多填.

## 发展

### 所需资源

-   节点.js 10

### 安装

```sh
git clone git@github.com:fastly/performance-observer-polyfill.git
cd performance-observer-polyfill
npm install
npm run build
```

## 运行

在开发绩效-观测-渗透功能的同时,您希望执行的大多数行动被定义为国家预防机制脚本,可以使用 `npm run {task}`。 。 。 .

所有命令及其描述的列表如下.

| 名称 | 说明 |
| --- | --- |
| 构建 | 编译生产环境应用程序 |
| 构建: dev | 编译开发应用程序 |
| 线性 | 使用 ESLint 将源文件用于样式错误, 并使用更漂亮的格式自动格式化源文件 |
| 测试 | 运行单元测试套件 |

## 许可证

[麻省理工学院](https://github.com/fastly/insights.js/blob/master/LICENSE)

## 常见问题

### @fastly/performance-observer-polyfill 是什么？

\* 业绩观察员

### 如何安装 @fastly/performance-observer-polyfill？

在项目目录运行 npm install @fastly/performance-observer-polyfill，或使用 pnpm add / yarn add / bun add。

### @fastly/performance-observer-polyfill 支持 TypeScript 吗？

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

### @fastly/performance-observer-polyfill 支持 ESM 还是 CommonJS？

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

### @fastly/performance-observer-polyfill 可以商用吗？

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

### @fastly/performance-observer-polyfill 的下载量有多少？

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

### @fastly/performance-observer-polyfill 还在维护吗？

最新版本 2\.0\.0 发布于 2021/02/23（5 年前）；至今共发布 12 个版本，其中过去 12 个月发布了 0 个；首次发布于 2019/06/13。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

