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 183 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
183 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
e41dd59
Fixup test: this test doesn't use the stylesheet assets so make sure …
eoghanmurray Oct 25, 2024
274a575
Fixup test, there's no significance in asset ordering
eoghanmurray Oct 25, 2024
557f5e5
Store the full URL for <style> assets as from a backend point of view…
eoghanmurray Nov 8, 2024
7c219d8
The `allAdded` flag no longer made sense in the context of multiple f…
eoghanmurray Nov 8, 2024
e8a9b4a
Guard against scenarios where preloadAllAssets is not called (came up…
eoghanmurray Nov 13, 2024
654e512
Fix for 'should list original url in non-live mode when asset never g…
eoghanmurray Nov 29, 2024
8d01e6e
This was failing again, so have reverted
eoghanmurray Nov 29, 2024
487b920
Don't capture small stylesheets as assets as timing issues are causin…
eoghanmurray Nov 29, 2024
1647e05
Ensure blocking class is respected to prevent processing of assets
eoghanmurray Dec 2, 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
Prev Previous commit
Next Next commit
WIP asset manager for replay
  • Loading branch information
Juice10 authored and eoghanmurray committed Oct 14, 2024
commit 0b18d21ccbc1e9f15469b9f2f88d5ce13df591e8
10 changes: 10 additions & 0 deletions packages/rrweb-snapshot/src/rebuild.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mediaSelectorPlugin, pseudoClassPlugin } from './css';
import {
type RebuildAssetManagerInterface,
type serializedNodeWithId,
type serializedElementNodeWithId,
type serializedTextNodeWithId,
@@ -157,6 +158,7 @@ function buildNode(
doc: Document;
hackCss: boolean;
cache: BuildCache;
assetManager?: RebuildAssetManagerInterface;
},
): Node | null {
const { doc, hackCss, cache } = options;
@@ -288,6 +290,13 @@ function buildNode(
'rrweb-original-srcset',
n.attributes.srcset as string,
);
} else if (
tagName === 'img' &&
n.attributes.src &&
options.assetManager
) {
// TODO: do something with the asset manager
console.log('WIP! Please implement me!');
} else {
node.setAttribute(name, value.toString());
}
@@ -416,6 +425,7 @@ export function buildNodeWithSN(
*/
afterAppend?: (n: Node, id: number) => unknown;
cache: BuildCache;
assetManager?: RebuildAssetManagerInterface;
},
): Node | null {
const {
65 changes: 65 additions & 0 deletions packages/rrweb/src/replay/assets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import type { RebuildAssetManagerInterface, assetEvent } from '@rrweb/types';
import { deserializeArg } from '../canvas/deserialize-args';

export default class AssetManager implements RebuildAssetManagerInterface {
private originalToObjectURLMap: Map<string, string> = new Map();
private loadingURLs: Set<string> = new Set();
private failedURLs: Set<string> = new Set();

public async add(event: assetEvent) {
const { data } = event;
const { url, payload, failed } = { payload: false, failed: false, ...data };
if (failed) {
this.failedURLs.add(url);
return;
}
this.loadingURLs.add(url);

// tracks if deserializing did anything, not really needed for AssetManager
const status = {
isUnchanged: true,
};

// TODO: extract the logic only needed for assets from deserializeArg
const result = (await deserializeArg(new Map(), null, status)(payload)) as
| Blob
| MediaSource;

const objectURL = URL.createObjectURL(result);
this.originalToObjectURLMap.set(url, objectURL);
this.loadingURLs.delete(url);
}

public get(
url: string,
):
| { status: 'loading' }
| { status: 'loaded'; url: string }
| { status: 'failed' }
| { status: 'unknown' } {
const result = this.originalToObjectURLMap.get(url);

if (result) {
return {
status: 'loaded',
url: result,
};
}

if (this.loadingURLs.has(url)) {
return {
status: 'loading',
};
}

if (this.failedURLs.has(url)) {
return {
status: 'failed',
};
}

return {
status: 'unknown',
};
}
}
6 changes: 3 additions & 3 deletions packages/rrweb/src/replay/index.ts
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ import getInjectStyleRules from './styles/inject-style';
import './styles/style.css';
import canvasMutation from './canvas';
import { deserializeArg } from './canvas/deserialize-args';
// import AssetManager from './assets';
import AssetManager from './assets';
import { MediaManager } from './media';
import { applyDialogToTopLevel, removeDialogFromTopLevel } from './dialog';

@@ -1049,11 +1049,11 @@ export class Replayer {
* Process all asset events and preload them
*/
private async preloadAllAssets(): Promise<void[]> {
// const assetManager = new AssetManager();
const assetManager = new AssetManager();
const promises: Promise<void>[] = [];
for (const event of this.service.state.context.events) {
if (event.type === EventType.Asset) {
// promises.push(assetManager.add(event));
promises.push(assetManager.add(event));
}
}
return Promise.all(promises);
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
101 changes: 101 additions & 0 deletions packages/rrweb/test/replay/asset-unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* @vitest-environment jsdom
*/

import AssetManager from '../../src/replay/assets';
import { EventType, SerializedBlobArg, assetEvent } from '@rrweb/types';
import { vi } from 'vitest';

describe('AssetManager', () => {
let assetManager: AssetManager;
let useURLPolyfill = false;
const examplePayload: SerializedBlobArg = {
rr_type: 'Blob',
type: 'image/png',
data: [
{
rr_type: 'ArrayBuffer',
base64: 'fake-base64-abcd',
},
],
};

beforeAll(() => {
// https://github.com/jsdom/jsdom/issues/1721
if (typeof window.URL.createObjectURL === 'undefined') {
useURLPolyfill = true;
window.URL.createObjectURL = () => '';
}
});

beforeEach(() => {
assetManager = new AssetManager();
});

afterEach(() => {
vi.restoreAllMocks();
});

afterAll(() => {
if (useURLPolyfill) {
delete (window.URL as any).createObjectURL;
}
});

it('should add an asset to the manager', async () => {
const url = 'https://example.com/image.png';

const event: assetEvent = {
type: EventType.Asset,
data: {
url,
payload: examplePayload,
},
};
const createObjectURLSpy = vi
.spyOn(URL, 'createObjectURL')
.mockReturnValue('objectURL');

await assetManager.add(event);

expect(createObjectURLSpy).toHaveBeenCalledWith(expect.any(Blob));
expect(assetManager.get(url)).toEqual({
status: 'loaded',
url: 'objectURL',
});
});

it('should not add a failed asset to the manager', async () => {
const url = 'https://example.com/image.png';
const event: assetEvent = {
type: EventType.Asset,
data: { url, failed: { message: 'failed to load file' } },
};
const createObjectURLSpy = vi.spyOn(URL, 'createObjectURL');

await assetManager.add(event);

expect(createObjectURLSpy).not.toHaveBeenCalled();
expect(assetManager.get(url)).toEqual({ status: 'failed' });
});

it('should return the correct status for a loading asset', () => {
const url = 'https://example.com/image.png';
const event: assetEvent = {
type: EventType.Asset,
data: {
url,
payload: examplePayload,
},
};
void assetManager.add(event);

expect(assetManager.get(url)).toEqual({ status: 'loading' });
});

it('should return the correct status for an unknown asset', () => {
const url = 'https://example.com/image.png';

expect(assetManager.get(url)).toEqual({ status: 'unknown' });
});
});
1 change: 1 addition & 0 deletions packages/rrweb/test/replay/video.test.ts
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ import { vi } from 'vitest';
import { Replayer } from '../../src/replay';
import videoPlaybackEvents from '../events/video-playback';
import videoPlaybackOnFullSnapshotEvents from '../events/video-playback-on-full-snapshot';
import type * as puppeteer from 'puppeteer';
expect.extend({ toMatchImageSnapshot });

type IWindow = typeof globalThis & Window & { replayer: Replayer };
24 changes: 19 additions & 5 deletions packages/types/src/index.ts
Copy link
Contributor

@Juice10 Juice10 Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self, we should pull these type changes into their own PR, to ease the release & maintenance of this PR. Especially where things have been moved from rrweb-snapshot to @rrweb/types

Original file line number Diff line number Diff line change
@@ -389,16 +389,18 @@ export enum CanvasContext {
WebGL2,
}

export type SerializedBlobArg = {
rr_type: 'Blob';
data: Array<CanvasArg>;
type?: string;
};

export type SerializedCanvasArg =
| {
rr_type: 'ArrayBuffer';
base64: string; // base64
}
| {
rr_type: 'Blob';
data: Array<CanvasArg>;
type?: string;
}
| SerializedBlobArg
| {
rr_type: string;
src: string; // url of image
@@ -727,6 +729,18 @@ export type TakeTypedKeyValues<Obj extends object, Type> = Pick<
TakeTypeHelper<Obj, Type>[keyof TakeTypeHelper<Obj, Type>]
>;

export abstract class RebuildAssetManagerInterface {
abstract add(event: assetEvent): Promise<void>;

abstract get(
url: string,
):
| { status: 'loading' }
| { status: 'loaded'; url: string }
| { status: 'failed' }
| { status: 'unknown' };
}

export enum NodeType {
Document,
DocumentType,