Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assets + stylesheet assets #1475

Open
wants to merge 176 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
176 commits
Select commit Hold shift + click to select a range
2b58e8d
Add Asset event type and capture assets
Juice10 Jun 8, 2023
7acc779
Add test to prove player works
Juice10 Jun 8, 2023
608ba0e
Rename `assetCaptureConfig` to `assetCapture`
Juice10 Jun 9, 2023
b20c8d5
Document `assetCapture` config
Juice10 Jun 9, 2023
ad775d8
Create asset event for assets that failed to load
Juice10 Jun 13, 2023
1294549
Move types from rrweb-snapshot to @rrweb/types
Juice10 Jun 13, 2023
0b18d21
WIP asset manager for replay
Juice10 Jun 13, 2023
2a92a9f
Add placeholder tests
Juice10 Nov 23, 2023
150396a
Fix image source attribute in rebuild function
Juice10 Nov 23, 2023
4a0dd26
Update path in tsconfig.json
Juice10 Nov 23, 2023
08114ee
Fix asset loading in Replayer
Juice10 Nov 23, 2023
bee80ed
Add todo tests
Juice10 Nov 23, 2023
c65dd0d
Add asset mutation events for replayer test
Juice10 Nov 24, 2023
9e5fb47
Add replay for cached asset on attribute changes
Juice10 Nov 24, 2023
d8ae854
Fix syntax error
Juice10 Nov 27, 2023
e2b181a
Move assetCapture params to @rrweb/types and add them to meta events
Juice10 Nov 27, 2023
a49cc54
Add asset capture config to meta events
Juice10 Nov 27, 2023
a5097a7
NodeType was moved to @rrweb/types
Juice10 Nov 27, 2023
f33f8ab
Upgrade jest and rollup in rrweb-snapshot
Juice10 Nov 27, 2023
dff274b
Add check types
Juice10 Nov 27, 2023
3802bd5
Update snapshots to include assetCapture settings
Juice10 Nov 28, 2023
5436839
Mark `inlineImages` as deprecated in favor of `assetCapture`
Juice10 Nov 28, 2023
60d1b42
Fix rrdom build
Juice10 Nov 28, 2023
561dcda
Fix deprecated test
Juice10 Nov 28, 2023
973222b
Rename `assetCapture` to `captureAssets`
Juice10 Nov 28, 2023
ee56ec5
Remove console.log statements from AssetManager
Juice10 Nov 28, 2023
e96793e
Rename assetCapture to captureAssets in rrweb test
Juice10 Nov 28, 2023
15eda9b
Check if url is of cacheable origin
Juice10 Nov 30, 2023
33030bc
Test: Add captureAssets config to meta event
Juice10 Nov 30, 2023
f21787b
object urls aren't stable so lets remove them
Juice10 Nov 30, 2023
69d0ade
inlineImages should work next to captureAssets for now
Juice10 Nov 30, 2023
b076708
Fix asset caching bug
Juice10 Dec 1, 2023
60b8bb1
captureAssets on live-stream by default
Juice10 Dec 1, 2023
20cd37e
Fix asset URLs in events file
Juice10 Dec 1, 2023
23f046c
Update deprecated inlineImages option to use
Juice10 Dec 4, 2023
a66e901
Deprecate inlineImage config
Juice10 Dec 4, 2023
ec55646
Update snapshot to reflect current captureAssets
Juice10 Dec 4, 2023
3bdc6c3
Make test less flaky
Juice10 Dec 4, 2023
3f45acb
Cache attribute support for BODY, TABLE,
Juice10 Dec 4, 2023
fa109af
Remove unused 'inlineImages' option
Juice10 Dec 4, 2023
dcb6d87
Refactor AssetManager constructor signature
Juice10 Dec 4, 2023
36dd426
Remove console.log statements in asset.test.ts
Juice10 Dec 4, 2023
2509e61
Refactor reset method signature to accept optional
Juice10 Dec 4, 2023
2d49f2a
Fix deserialized size comparison in deserializeArg
Juice10 Dec 4, 2023
40d0513
Apply formatting changes
Juice10 Dec 4, 2023
6201623
Fix asset manager to only load assets from
Juice10 Dec 4, 2023
4f2c30d
Update defaultPort in startServer function
Juice10 Dec 4, 2023
66a8438
Make test more reliable
Juice10 Dec 4, 2023
f723f72
Add failing test for src attribute
Juice10 Dec 11, 2023
0dc35d4
Remove failed asset event
Juice10 Dec 11, 2023
a75c8c6
Add support for asset manager in rrdom
Juice10 Dec 12, 2023
ffb6daf
Change asset manager path
Juice10 Dec 14, 2023
25184e7
Fix import path for AssetManager in asset-unit.test.ts
Juice10 Dec 14, 2023
83a3ed1
Move isAttributeCacheable tests to rrweb-snapshot
Juice10 Dec 14, 2023
be1b471
Make assetManager optional
Juice10 Dec 14, 2023
480f99c
upgrade rrdom-nodejs to jest 29
Juice10 Dec 14, 2023
ba20659
fixup! Upgrade jest and rollup in rrweb-snapshot
eoghanmurray Aug 6, 2024
53f448b
Update Jest and ts-jest versions to 29 in rrvideo
Juice10 Dec 14, 2023
1491719
Following https://stackoverflow.com/a/64167731 on rebas
eoghanmurray Aug 6, 2024
f689be1
Following https://stackoverflow.com/a/64167731 on rebase #2
eoghanmurray Aug 6, 2024
43d4256
Add esModuleInterop and allowSyntheticDefaultImports to tsconfig.json
Juice10 Dec 14, 2023
bf3e0fe
Add support for updating srcset attribute in
Juice10 Dec 15, 2023
9b27177
Add support for SVG elements in AssetManager
Juice10 Dec 15, 2023
0bd373c
Drop support for caching xlink:href attributes
Juice10 Dec 15, 2023
6ffcc67
Remove console.log statement in
Juice10 Dec 15, 2023
04d806e
Linux and Mac generate slightly different screenshots
Juice10 Dec 15, 2023
6b09ff3
Remove syntax error
Juice10 Dec 15, 2023
6b9353a
Add wait for RAF before evaluating snapshots
Juice10 Dec 15, 2023
7b8358e
Changeset: Added support for Asset Event and capturing many
Juice10 Dec 15, 2023
b45b5cf
fixup! Add support for updating srcset attribute in AssetManager
eoghanmurray Jul 4, 2024
ebe0d25
Update puppeteer version in package.json
Juice10 Jan 16, 2024
e678f46
Fix cross-origin iframe message forwarding test
Juice10 Jan 16, 2024
2181c25
Make test more robust
Juice10 Jan 16, 2024
548bd24
Deprecate `inlineImages` and introduce `captureAssets` option
Juice10 Feb 5, 2024
968f4fe
Docs: add examples to `getUrlsFromSrcset`
Juice10 Feb 5, 2024
6fd25a2
Revert accidental change to `backToNormal`
Juice10 Feb 5, 2024
3b8b974
Move @rrweb/types to devDependencies for rrweb-snapshot
Juice10 Feb 6, 2024
eb39d08
Remove console.log statements in asset-integration.test.ts
Juice10 Mar 18, 2024
68e7815
Update packages/rrweb/src/replay/asset-manager/index.ts
Juice10 Mar 20, 2024
4d3ba68
Delay call until all attributes are present on the new node, in case …
eoghanmurray Mar 25, 2024
8ca75f8
Rename Cacheable -> Capturable
eoghanmurray Mar 25, 2024
8de02d1
Apply formatting changes
Juice10 May 22, 2024
af547a3
Apply formatting changes
Juice10 Jun 9, 2024
f9c4f6c
Apply formatting changes
Juice10 Jun 9, 2024
00cd080
Trigger CI again
Juice10 Jun 9, 2024
c833878
Apply formatting changes
Juice10 Jun 9, 2024
c7eeb1e
Need to import NodeType directly, not working after some combination …
eoghanmurray Jun 15, 2024
6f02664
Fix typo in deprecated test
eoghanmurray Jun 18, 2024
1f55cee
Make test less flaky
Juice10 Dec 4, 2023
4d884d6
add @types/prettier dependency
Juice10 Dec 14, 2023
8fc8837
Indicate the presence of deferred assets using new `rr_captured_*` at…
eoghanmurray Mar 25, 2024
9556922
Revert attributes in non-live mode and ensure this happens when we ca…
eoghanmurray Mar 27, 2024
7c5beef
Only record certain iframes as assets as we don't want to override th…
eoghanmurray Mar 27, 2024
a561c33
Fixup: we don't need template strings here
eoghanmurray Mar 28, 2024
134374f
Ensure we correctly distinguish between html <iframes> and other exot…
eoghanmurray Mar 28, 2024
ed0d5ab
Bump timeouts here as I was getting failures when running whole test …
eoghanmurray Mar 28, 2024
d3534be
Add an `asset` type which includes the element; a bit of prep work fo…
eoghanmurray Mar 28, 2024
8a06c49
This function was replaced by getSourcesFromSrcset which ultimately d…
eoghanmurray Apr 2, 2024
bb33dba
Refactor and prepare for some changes: Deal with the difference betwe…
eoghanmurray Apr 3, 2024
cae9720
Create assetStatus type as per Justin's request
eoghanmurray Apr 3, 2024
e39ee96
Fix types as per suggestions from code review
Juice10 Apr 5, 2024
4429182
Update packages/rrweb/src/replay/canvas/2d.ts
Juice10 Apr 5, 2024
2ada9a1
Don't rename attrs of assets which will be refused according to initi…
eoghanmurray Apr 22, 2024
7e17722
New config option inlineStylesheet='all' in order to fetch stylesheet…
eoghanmurray Apr 24, 2024
77d8a83
Simplify onAssetDetected function signature
eoghanmurray Apr 25, 2024
3254dec
Don't double capture blobs as _cssText and an asset. Fixes test 'capt…
eoghanmurray Apr 25, 2024
f4a88f5
Prefer to inlineStylesheets using Assets so that we can take advantag…
eoghanmurray Apr 25, 2024
1c78feb
No need to search through document.styleSheets as the sheet property …
eoghanmurray Apr 26, 2024
bbec8e8
Improvements to comments on buildStyleNode (don't want to rebase as i…
eoghanmurray May 1, 2024
50d4953
Capture <style> element css via an asset event to avoid main thread p…
eoghanmurray May 2, 2024
578bcdf
Add a slight delay as per #1455
eoghanmurray Apr 30, 2024
7bc516d
Allow certain assets to be captured synchronously during mutation
eoghanmurray Apr 30, 2024
d03a53c
Add setting to control how quickly stylesheet assets get emitted - so…
eoghanmurray May 1, 2024
3fcbc79
Don't queue up asset callbacks twice; was happening after `replayer.p…
eoghanmurray May 1, 2024
396dd0c
We can rebuild styles immediately without the async/promise delay tha…
eoghanmurray May 1, 2024
84618b7
When we rebuild styles immediately from a snapshot, ensure we are cor…
eoghanmurray May 1, 2024
91a1e1d
Didn't realize we can use the 'as' keyword to treat an rrdom element …
eoghanmurray May 1, 2024
d555c09
Fix up an issue with the assumption that origins applies only to images
eoghanmurray May 1, 2024
ada0769
Restore `inlineImages` as a first class config option which bypasses …
eoghanmurray May 9, 2024
6554bf1
Remove tests that are duplicated minus the 'if inlineImages is on' pa…
eoghanmurray May 1, 2024
a6b520b
Don't emit style mutations if we haven't serialized the style sheet y…
eoghanmurray May 1, 2024
8f3c65d
Replicate the 'removing style elements' test but with an asset
eoghanmurray May 2, 2024
eaa0f09
Catch and fix omission of absoluteToStylesheet processing on style te…
eoghanmurray May 2, 2024
a912e16
Add a try/catch here as we may not be reading anchor.href
eoghanmurray May 2, 2024
dea66b5
Explore how we capture assets that have disappeared from the DOM
eoghanmurray May 2, 2024
2482503
Add some notes after considering changing these to use assets
eoghanmurray May 3, 2024
b1e7ab4
Add explanation as to why we are patching createObjectURL
eoghanmurray May 3, 2024
61e5fba
Idea from Justin: Store cssText as an array rather than with the extr…
eoghanmurray May 8, 2024
a57bc5c
Allow usage of requestIdleCallback to be turned off altogether by set…
eoghanmurray May 8, 2024
019b44e
requestIdleCallback: Process inline <style> elements before <link rel…
eoghanmurray May 8, 2024
0a42bdc
Simplify by passing the inlineStylesheets config setting around as pa…
eoghanmurray May 9, 2024
cdb2363
These settings are not 'inlining' in the snapshot but rather producin…
eoghanmurray May 9, 2024
9fa0289
Transfer the legacy default setting into a special 'without-fetch' in…
eoghanmurray May 9, 2024
433e93c
Enable all capturing of stylesheets via assets to be turned off
eoghanmurray May 9, 2024
703b7f9
Add a setting to enable turning off of assets for smaller stylesheets…
eoghanmurray May 13, 2024
44542a3
Properly handle a loading CORS stylesheet as a mutation + asset rathe…
eoghanmurray May 13, 2024
5ebe721
Rewrite of assets.md and move out of recipes into core docs
eoghanmurray May 14, 2024
999cc32
Apply formatting changes
eoghanmurray May 14, 2024
18c44eb
Satisfy eslint
eoghanmurray May 15, 2024
92dbf7f
Satisfy typescript by creating an Interface to acknowledge the extra …
eoghanmurray May 16, 2024
6911010
Don't just re-assert 'detected' in the explanatory comment
eoghanmurray May 20, 2024
ed4fb11
Prefer waitForRAF over timeout as the latter operates in puppeteer ra…
eoghanmurray May 22, 2024
e0327f0
Update assets.zh_CN.md
YunFeng0817 May 22, 2024
5e43f37
Remove doubly added prettier reference
eoghanmurray Jun 18, 2024
ad7ce45
Fixup expected server url; presumably this is a side effect of switch…
eoghanmurray Jun 18, 2024
157a256
Fixup test: maybe vite doesn't incorrectly produce this dupe?
eoghanmurray Jun 18, 2024
6763c08
Continue fixes from #1510
eoghanmurray Jun 18, 2024
6bd9b47
Extra pause needed after switch from jest to vitest, when running tes…
eoghanmurray Jun 21, 2024
f3fa35d
Fixups to imports; I'm not sure where this all went wrong in the reba…
eoghanmurray Jul 4, 2024
ec60cef
fixup! Caught a case where a text mutation, which bypasses `_cssText`…
eoghanmurray Jul 10, 2024
2d5afc4
This was removed in single-style-capture but 'reintroduced' in this h…
eoghanmurray Jul 10, 2024
8aa7388
Fix that the `false` default on `shouldIgnoreAssets` should have been…
eoghanmurray Jul 10, 2024
c71393e
Fix that we would have tried to capture an asset with a malformed url…
eoghanmurray Jul 10, 2024
c12e649
Honour the 'omits css contents for asset managed stylesheet' test:
eoghanmurray Jul 10, 2024
403313c
Improve consistency in terms of where in the test the asset appears
eoghanmurray Jul 10, 2024
d1ca7ac
Apply formatting changes
eoghanmurray Jul 10, 2024
7f4aaca
Prior to this PR, we weren't previously storing blank _cssText; could…
eoghanmurray Jul 10, 2024
3faa4de
Improve test reliability
eoghanmurray Jul 10, 2024
084bf88
Think we need tighter processing for the tests to pass in the CI - pr…
eoghanmurray Jul 10, 2024
9cad5cb
These tests were showing variation in CI
eoghanmurray Jul 12, 2024
b73ad96
fixup! Move types from rrweb-snapshot to @rrweb/types
eoghanmurray Aug 7, 2024
30ffbfb
fixup! Add esModuleInterop and allowSyntheticDefaultImports to tsconf…
eoghanmurray Aug 7, 2024
7a87075
fixup! Move types from rrweb-snapshot to @rrweb/types
eoghanmurray Aug 15, 2024
27cab92
Unknown changes to yarn.lock
eoghanmurray Aug 15, 2024
f86f182
fixup! Move types from rrweb-snapshot to @rrweb/types
eoghanmurray Aug 20, 2024
c7edb29
Apply formatting changes
eoghanmurray Aug 20, 2024
faad2d5
Add a queueing mechanism so that in Live Mode we don't render full sn…
eoghanmurray Aug 20, 2024
8aa60b6
assetCount would not suffice if multiple FullSnapshots were present i…
eoghanmurray Oct 11, 2024
8f82519
Satisfy typings
eoghanmurray Oct 14, 2024
b42878b
Apply formatting changes
eoghanmurray Oct 14, 2024
ab90b43
Mark where I think the assetManager resets were supposed to happen as…
eoghanmurray Oct 18, 2024
ba28b86
More accurate setting of 'allAdded' based on how asset urls compare t…
eoghanmurray Oct 18, 2024
b130837
Allow duplicate assets to only be sent once per recording (e.g. in a …
eoghanmurray Oct 23, 2024
08415f4
`buildNodeWithSN` still lives in rrweb-snapshot - correction for 'Mov…
eoghanmurray Oct 23, 2024
a79f253
Fixup test: this test doesn't use the stylesheet assets so make sure …
eoghanmurray Oct 25, 2024
2641cde
Fixup test, there's no significance in asset ordering
eoghanmurray Oct 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/pretty-candles-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"rrweb-snapshot": minor
"rrweb": minor
"rrdom": patch
"@rrweb/types": patch
---

Added support for Asset Event and capturing many different types of assets (not just img#src)
8 changes: 8 additions & 0 deletions .changeset/yellow-vans-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"rrweb-snapshot": major
"@rrweb/types": patch
---

`NodeType` enum was moved from rrweb-snapshot to @rrweb/types
The following types where moved from rrweb-snapshot to @rrweb/types: `documentNode`, `documentTypeNode`, `attributes`, `legacyAttributes`, `elementNode`, `textNode`, `cdataNode`, `commentNode`, `serializedNode`, `serializedNodeWithId` and `DataURLOptions`
`inlineImage` config option is deprecated and in `rrweb` is an alias for `captureAssets` config option
4 changes: 2 additions & 2 deletions .github/workflows/style-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ jobs:
runs-on: ubuntu-latest
name: Format Code
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}
- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'yarn'
Expand Down
66 changes: 66 additions & 0 deletions docs/assets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Asset Capture Methods & Configuration in rrweb

[rrweb](https://rrweb.io/) is a JavaScript library that allows you to record and replay user interactions on your website. It provides various configuration options for capturing assets (such as images) during the recording process. In this document, we will explore the different asset capture methods and their configuration options in rrweb.

## Asset Events

Assets are a new type of event that embody a serialized version of a http resource captured during snapshotting. Some examples are images, media files and stylesheets. Resources can be fetched externally (from cache) in the case of a href, or internally for blob: urls and same-origin stylesheets. Asset events are emitted subsequent to either a FullSnapshot or an IncrementalSnapshot (mutation), and although they may have a later timestamp, during replay they are rebuilt as part of the snapshot that they are associated with. In the case where e.g. a stylesheet is referenced at the time of a FullSnapshot, but hasn't been downloaded yet, there can be a subsequent mutation event with a later timestamp which, along with the asset event, can recreate the experience of a network-delayed load of the stylesheet.

## Assets to mitigate stylesheet processing cost

In the case of stylesheets, rrweb does some record-time processing in order to serialize the css rules which had a negative effect on the initial page loading times and how quickly the FullSnapshot was taken (see https://pagespeed.web.dev/). These are now taken out of the main thread and processed asynchronously to be emitted (up to `processStylesheetsWithin` ms) later. There is no corresponding delay on the replay side so long as the stylesheet has been successfully emitted.

## Asset Capture Configuration

The `captureAssets` configuration option allows you to customize the asset capture process. It is an object with the following properties:

- `objectURLs` (default: `true`): This property specifies whether to capture same-origin `blob:` assets using object URLs. Object URLs are created using the `URL.createObjectURL()` method. Setting `objectURLs` to `true` enables the capture of object URLs.

- `origins` (default: `false`): This property determines which origins to capture assets from. It can have the following values:

- `false` or `[]`: Disables capturing any assets apart from object URLs, stylesheets (unless set to false) and images (if that setting is turned on).
- `true`: Captures assets from all origins.
- `[origin1, origin2, ...]`: Captures assets only from the specified origins. For example, `origins: ['https://s3.example.com/']` captures all assets from the origin `https://s3.example.com/`.

- `images` (default: `false` or `true` if `inlineImages` is true in rrweb.record config): When set, this option turns on asset capturing for all images irrespective of their origin. When this configuration option is false, images may still be captured if their src url matches the `origins` setting above.

- `stylesheets` (default: `'without-fetch'`): When set to `true`, this turns on capturing of all stylesheets and style elements via the asset system irrespective of origin. The default of `'without-fetch'` is designed to match with the previous `inlineStylesheet` behaviour, whereas the `true` value allows capturing of stylesheets which are otherwise inaccessible due to CORS restrictions to be captured via a fetch call, which will normally use the browser cache. If a stylesheet matches via the `origins` config above, it will be captured irrespective of this config setting (either directly or via fetch).

- `stylesheetsRuleThreshold` (default: `0`): only invoke the asset system for stylesheets with more than this number of rules. Defaults to zero (rather than say 100) as it only looks at the 'outer' rules (e.g. could have a single media rule which nests 1000s of sub rules). This default may be increased based on feedback.

- `processStylesheetsWithin` (default: `2000`): This property defines the maximum time in milliseconds that the browser should delay before processing stylesheets. Inline `<style>` elements will be processed within half this value. Lower this value if you wish to improve the odds that short 'bounce' visits will emit the asset before visitor unloads page. Set to zero or a negative number to process stylesheets synchronously, which can cause poor scores on e.g. https://pagespeed.web.dev/ ("Third-party code blocked the main thread").

## TypeScript Type Definition

Here is the TypeScript type definition for the `recordOptions` object, which includes the asset capture configuration options:

```typescript
export type recordOptions<T> = {
// Other configuration options...
captureAssets?: {
objectURLs: boolean;
origins: string[] | true | false;
images: boolean;
stylesheets: boolean | 'without-fetch';
processStylesheetsWithin: number;
stylesheetsRuleThreshold: number;
};
inlineImages?: boolean;
inlineStylesheet?: boolean;
// Other configuration options...
};
```

This type definition shows that `captureAssets` is an optional property of the `recordOptions` object. It contains the `objectURLs` and `origins` properties, which have the same meanings as described above.

## Inline Images

When set in rrweb.record, the previous `inlineImages` configuration option has been changed so that images are now captured using the asset system instead of being inlined into the snapshot. The previous implementation had a problem in that the snapshot was modified asynchronously after images were loaded/processed. hadn't loaded yet, and the snapshot may have already been emitted. When using rrwebSnapshot.snapshot directly, the previous inlining behaviour is still preserved.

## Inline Stylesheets

In rrweb.record the `inlineStylesheet` configuration option has been updated to use the asset system. When it is `true` (the default), stylesheets whose rules are accessible from a CORS point of view are captured as an asset instead of being inlined. There is also now an `inlineStylesheet: 'all'` option which is equivalent to `captureAssets.stylesheets: true`. When using rrwebSnapshot.snapshot directly, the previous inlining behaviour is still preserved.

## Conclusion

By configuring the `captureAssets` option in rrweb, you can control how assets like images are captured during the recording process. This allows you to customize which assets are included in the recorded interactions on your website.
40 changes: 40 additions & 0 deletions docs/assets.zh_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# rrweb 中的录制静态资源的方法和配置

[rrweb](https://rrweb.io/) 是一个 JavaScript 库,允许您录制并回放您网页上的用户操作。它为录制静态资源(如图像)提供了各种配置选项。在本文档中,我们将探讨 rrweb 中不同的录制静态资源的方法及其配置选项。

## 内联图像(已弃用)

`inlineImages` 配置选项已被弃用,不应再使用。它存在一些问题,即重写已经发出的事件,这可能使您错过已发送到服务器的内联图像。相反,请使用 `captureAssets` 选项来配置静态资源录制。

## 录制静态资源配置

`captureAssets` 配置选项允许您自定义录制静态资源的过程。它是一个具有以下属性的对象:

- `objectURLs`(默认值:`true`):此属性指定是否使用 object URL 录制同源 `blob:` 资源。Object URL 是使用 `URL.createObjectURL()` 方法创建的。将 `objectURLs` 设置为 `true` 可以启用对象 URL 的录制。

- `origins`(默认值:`false`):此属性确定录制哪些域名的资源。它可以有以下值:
- `false` 或 `[]`:除了 Object URL 之外,不录制任何静态资源。
- `true`:从所有来源获取资源。
- `[origin1, origin2, ...]`:仅从指定的来源获取资源。例如,`origins: ['https://s3.example.com/']` 表示录制来自 `https://s3.example.com/` 的所有静态资源。

## TypeScript 类型定义

这是 `recordOptions` 对象的 TypeScript 类型定义,其中包括录制静态资源的配置选项:

```typescript
export type recordOptions<T> = {
// 其他配置选项...
captureAssets?: {
objectURLs: boolean;
origins: string[] | true | false;
};
inlineImages?: boolean; // 已弃用
// 其他配置选项...
};
```

这种类型定义表明 captureAssets 是 recordOptions 对象的一个可选属性。它包含 objectURLs 和 origins 属性,其含义与上述相同。

## 结论

通过在 rrweb 中配置 captureAssets 选项,您可以控制在记录过程中如何录制比如图像这样的静态资源。这允许你自定义在网页上录制的交互中包含哪些静态资源。
Loading
Loading