From a5f6cb92c7254e532cce3a66669e0f31ebb2b218 Mon Sep 17 00:00:00 2001 From: Yanzhen Yu Date: Wed, 1 Apr 2026 12:00:00 +0800 Subject: [PATCH] update docs --- README.md | 46 +++------- README.zh_CN.md | 11 +++ guide.md | 237 ++++++++++++++++++++++++++++++++++++++++++++++++ guide.zh_CN.md | 63 +++++++++++++ 4 files changed, 325 insertions(+), 32 deletions(-) create mode 100644 guide.md diff --git a/README.md b/README.md index 61019d3f..111c37ea 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,10 @@ +

+ +

+

+ Try rrweb +

+ # rrweb [![Build Status](https://travis-ci.org/rrweb-io/rrweb.svg?branch=master)](https://travis-ci.org/rrweb-io/rrweb) @@ -8,6 +15,10 @@ rrweb refers to 'record and replay the web', which is a tool for recording and r **Currently, rrweb has already solved many difficult problems in recording and replaying, but the data structure may still be changed before the release of Version 1.0. So please be cautious to use rrweb in the production environment.** +## Guide + +[**📚 Read the rrweb guide here. 📚**](./guide.md) + ## Project Structure rrweb is mainly composed of 3 parts: @@ -31,12 +42,12 @@ rrweb is mainly composed of 3 parts: - hijack Ajax/fetch API and record request events - use TraceKit to log exception events -## Internal Design + ## Contribute Guide @@ -51,33 +62,4 @@ Since we want the record and replay sides to share a strongly typed data structu In addition to adding integration tests and unit tests, rrweb also provides a REPL testing tool. -Run `npm run repl` to launch a browser and ask for a URL you want to test on the CLI: - -``` -Enter the url you want to record, e.g https://react-redux.realworld.io: -``` - -Waiting for the browser to open the specified page and print following messages on the CLI: - -``` -Enter the url you want to record, e.g https://react-redux.realworld.io: https://github.com -Going to open https://github.com... -Ready to record. You can do any interaction on the page. -Once you want to finish the recording, enter 'y' to start replay: -``` - -At this point, you can interact in the web page. After the desired operations have been recorded, enter 'y' on the CLI, and the test tool will replay the operations to verify whether the recording was successful. - -The following messages will be printed on the CLI during replay: - -``` -Enter 'y' to persistently store these recorded events: -``` - -At this point, you can enter 'y' again on the CLI. The test tool will save the recorded session into a static HTML file and prompt for the location: - -``` -Saved at PATH_TO_YOUR_REPO/temp/replay_2018_11_23T07_53_30.html -``` - -This file uses the latest rrweb bundle code, so we can run `npm run bundle:browser` after patching the code, then refresh the static file to see and debug the impact of the latest code on replay. +[Using the REPL tool](./guide.md#REPL-tool) diff --git a/README.zh_CN.md b/README.zh_CN.md index 3c71a4c5..9458e755 100644 --- a/README.zh_CN.md +++ b/README.zh_CN.md @@ -1,3 +1,10 @@ +

+ +

+

+ Try rrweb +

+ # rrweb [![Build Status](https://travis-ci.org/rrweb-io/rrweb.svg?branch=master)](https://travis-ci.org/rrweb-io/rrweb) @@ -6,6 +13,10 @@ rrweb 是 'record and replay the web' 的简写,旨在利用现代浏览器所 **目前 rrweb 已经解决了许多录制与回放中的难点问题,但在 1.0 版本 release 之前数据结构仍有可能发生变化,请谨慎用于生产环境中。** +## 指南 + +[**📚 rrweb 使用指南 📚**](./guide.zh_CN.md) + ## 项目结构 rrweb 主要由 3 部分组成: diff --git a/guide.md b/guide.md new file mode 100644 index 00000000..59b58588 --- /dev/null +++ b/guide.md @@ -0,0 +1,237 @@ +# Guide + +[中文指南](./guide.zh_CN.md) + +## Installation + +### Direct ` +``` + +Also, you can link to a specific version number that you can update manually: + +```html + +``` + +#### Only include the recorder code + +rrweb's code includes both the record and the replay parts. Most of the time you only need include the record part into your target web Apps. +This also can be done by using the CDN service: + +```html + +``` + +### NPM + +```shell +npm install --save rrweb +``` + +rrweb provides both commonJS and ES modules bundles, which is easy to use with the popular bundlers. + +## Getting Started + +### Record + +If you only include record code with ` +``` + +Or installed by using NPM: + +```shell +npm install --save rrweb-player +``` + +##### Usage + +```js +new rrwebPlayer({ + target: document.body, // customizable root element + data: { + events, + }, +}); +``` + +## API + +### rrweb + +#### rrweb.record + +```typescript +type record = (options: recordOptions) => listenerHandler; + +type recordOptions = { + emit: (e: eventWithTime) => void; +}; +type listenerHandler = () => void; +``` + +#### rrweb.Replayer + +```typescript +class Replayer { + public wrapper: HTMLDivElement; + + constructor(events: eventWithTime[], config?: Partial); + + public on(event: string, handler: mitt.Handler): void; + public setConfig(config: Partial): void; + public getMetaData(): playerMetaData; + public getTimeOffset(): number; + public play(timeOffset?: number): void; + public pause(): void; + public resume(timeOffset?: number): void; +} + +type playerConfig = { + speed: number; + root: Element; + loadTimeout: number; + skipInactive: Boolean; +}; + +type playerMetaData = { + totalTime: number; +}; +``` + +## REPL tool + +You can also play with rrweb by using the REPL testing tool which does not need installation. + +Run `npm run repl` to launch a browser and ask for a URL you want to test on the CLI: + +``` +Enter the url you want to record, e.g https://react-redux.realworld.io: +``` + +Waiting for the browser to open the specified page and print following messages on the CLI: + +``` +Enter the url you want to record, e.g https://react-redux.realworld.io: https://github.com +Going to open https://github.com... +Ready to record. You can do any interaction on the page. +Once you want to finish the recording, enter 'y' to start replay: +``` + +At this point, you can interact in the web page. After the desired operations have been recorded, enter 'y' on the CLI, and the test tool will replay the operations to verify whether the recording was successful. + +The following messages will be printed on the CLI during replay: + +``` +Enter 'y' to persistently store these recorded events: +``` + +At this point, you can enter 'y' again on the CLI. The test tool will save the recorded session into a static HTML file and prompt for the location: + +``` +Saved at PATH_TO_YOUR_REPO/temp/replay_2018_11_23T07_53_30.html +``` + +This file uses the latest rrweb bundle code, so we can run `npm run bundle:browser` after patching the code, then refresh the static file to see and debug the impact of the latest code on replay. diff --git a/guide.zh_CN.md b/guide.zh_CN.md index d7a977cb..15dd95bb 100644 --- a/guide.zh_CN.md +++ b/guide.zh_CN.md @@ -81,6 +81,14 @@ function save() { setInterval(save, 10 * 1000); ``` +#### 隐私 + +页面中可能存在一些隐私相关的内容不希望被录制,rrweb 为此做了以下支持: + +- 在 HTML 元素中添加类名 `.rr-block` 将会避免该元素及其子元素被录制,回放时取而代之的是一个同等宽高的占位元素。 +- 在 HTML 元素中添加类名 `.rr-ignore` 将会避免录制该元素的输入事件。 +- `input[type="password"]` 类型的密码输入框默认不会录制输入事件。 + ### 回放 回放时需要引入对应的 CSS 文件: @@ -101,6 +109,17 @@ const replayer = new rrweb.Replayer(events); replayer.play(); ``` +#### 配置参数 + +可以通过 `new rrweb.Replayer(events, options)` 的方式向 rrweb 传递回放时的配置参数,具体配置如下: + +| key | 默认值 | 功能 | +| ----- | ------------- | -------- | +| speed | 1 | 回放倍速 | +| root | document.body | 回放时使用的 HTML 元素 | +| loadTimeout | 0 | 加载异步样式表的超时时长 | +| skipInactive | false | 是否快速跳过无用户操作的阶段 | + #### 使用 rrweb-player rrweb 自带的回放只提供所有的 JS API 以及最基本的 UI,如果需要更强的回放播放器 UI,可以使用 rrweb-player。 @@ -134,6 +153,50 @@ new rrwebPlayer({ }); ``` +## API + +### rrweb + +#### rrweb.record + +```typescript +type record = (options: recordOptions) => listenerHandler; + +type recordOptions = { + emit: (e: eventWithTime) => void; +}; +type listenerHandler = () => void; +``` + +#### rrweb.Replayer + +```typescript +class Replayer { + public wrapper: HTMLDivElement; + + constructor(events: eventWithTime[], config?: Partial); + + public on(event: string, handler: mitt.Handler): void; + public setConfig(config: Partial): void; + public getMetaData(): playerMetaData; + public getTimeOffset(): number; + public play(timeOffset?: number): void; + public pause(): void; + public resume(timeOffset?: number): void; +} + +type playerConfig = { + speed: number; + root: Element; + loadTimeout: number; + skipInactive: Boolean; +}; + +type playerMetaData = { + totalTime: number; +}; +``` + ## REPL 工具 在不安装 rrweb 的情况下,也可以通过使用 REPL 工具试用 rrweb 录制 web 应用。