impl #81 custom event

This is the record side impl of custom event, according to the
issue, we may also add first-class support for the custom event
tag like display color labels in the replayer-ui.
This commit is contained in:
Yanzhen Yu
2026-04-01 12:00:00 +08:00
parent 469dbd5dee
commit d92a946926
5 changed files with 139 additions and 5 deletions

View File

@@ -23,6 +23,7 @@ interface ISuite extends Suite {
interface IWindow extends Window {
rrweb: {
record: (options: recordOptions) => listenerHandler | undefined;
addCustomEvent<T>(tag: string, payload: T): void;
};
emit: (e: eventWithTime) => undefined;
}
@@ -180,4 +181,19 @@ describe('record', function(this: ISuite) {
await this.page.waitFor(50);
assertSnapshot(this.events, __filename, 'async-checkout');
});
it('can add custom event', async () => {
await this.page.evaluate(() => {
const { record, addCustomEvent } = (window as IWindow).rrweb;
record({
emit: (window as IWindow).emit,
});
addCustomEvent<number>('tag1', 1);
addCustomEvent<{ a: string }>('tag2', {
a: 'b',
});
});
await this.page.waitFor(50);
assertSnapshot(this.events, __filename, 'custom-event');
});
});