# @expo/browser-polyfill 中文文档

规范地址：https://npmcn.com/package/%40expo/browser-polyfill/

版本：1\.0\.1
npm 元数据更新时间：2026-09-23T11:26:08.093Z
中文译文更新时间：2026-11-14T05:28:35.798Z
软件包许可：MIT

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

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

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

- 包体积（解压后）：21 kB，19 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：5 个
- peer 依赖：react ^17\.0\.1，react-native ^0\.64\.3，expo-file-system ^13\.2\.0
- 首次发布：2018-02-10T00:13:22.906Z
- 最新版本发布：2024-04-24T08:56:19.713Z
- 近 30 天下载量：132433（2026-10-14 至 2026-11-12，npm 官方下载统计）
- 已发布版本数：22（近 12 个月 0 个）

## 中文简介

浏览器多填充, 使 React Introduct 与 pixi.js 等 web libs相容, 3.js, 相相相相相相通 js

## 安装

```sh
npm install @expo/browser-polyfill
```

也可以使用：`pnpm add @expo/browser-polyfill`、`yarn add @expo/browser-polyfill`、`bun add @expo/browser-polyfill`

## README

# @ expo/ 浏览器- 填充

React 原生浏览器多填充

### 安装

```bash
yarn add @expo/browser-polyfill
```

### 使用量

将库导入您的 JavaScript 文件 :

```js
import '@expo/browser-polyfill';
```

## 执行

## 管理部

DOM得到的支持非常低,这些用于像验证类型的pixi.js这样的libs.

```js
class Node
class Element
class Document
class HTMLImageElement
class Image
class ImageBitmap
class HTMLVideoElement
class Video
class HTMLCanvasElement
class Canvas
```

### 图像, HTML 图像元素, 图像比特地图

图像支持装入回调, 但是装入的 uri 必须已经传递到 src .

```js
const image = new Image();
image.src = '';
image.onload = () => {
  const { src, width, height } = image;
};
image.addEventListener('loading', () => {});
image.addEventListener('error', () => {});
```

### 文档

```js
const element = document.createElement('div');
const fakeContext = element.getContext('');
```

### 元素

#### 所有大小返回窗口大小 :

```js
element.clientWidth;
element.clientHeight;
element.innerWidth;
element.innerHeight;
element.offsetWidth;
element.offsetHeight;
```

#### 防止库崩溃的空属性

```js
element.tagName;
element.addEventListener;
element.removeEventListener;
element.setAttributeNS;
element.createElementNS;
```

### 节点

```js
node.ownerDocument;
node.className;
node.appendChild;
node.insertBefore;
node.removeChild;
node.setAttributeNS;
node.getBoundingClientRect;
```

# 外部图书馆

一些外接节点.js多填充器也被添加.

## [文本编码](https://github.com/inexorabletash/text-encoding)

```
global.TextEncoder
global.TextDecoder
```

## [页:1](https://github.com/zeligzhou/xmldom-qsa)

```
window.DOMParser
```

## [反应-内置-控制器-时间-填充](https://github.com/MaxGraey/react-native-console-time-polyfill)

```
console.time(label);
console.timeEnd(label);
console.count(label);
```

# 除错旗

对于调试 Base64 图像转换切换:

```js
global.__debug_browser_polyfill_image = true;
```

默认 `global.__debug_browser_polyfill_image` 是虚假的.

## 常见问题

### @expo/browser-polyfill 是什么？

浏览器多填充, 使 React Introduct 与 pixi\.js 等 web libs相容, 3\.js, 相相相相相相通 js

### 如何安装 @expo/browser-polyfill？

在项目目录运行 npm install @expo/browser-polyfill，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：react（^17\.0\.1）、react-native（^0\.64\.3）、expo-file-system（^13\.2\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @expo/browser-polyfill 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/expo\_\_browser-polyfill 是否存在。

### @expo/browser-polyfill 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @expo/browser-polyfill 可以商用吗？

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

### @expo/browser-polyfill 的下载量有多少？

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

### @expo/browser-polyfill 还在维护吗？

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

