@@ -1,4 +1,4 @@
|
|||||||
import record from './record';
|
import record, { addCustomEvent } from './record';
|
||||||
import { Replayer } from './replay';
|
import { Replayer } from './replay';
|
||||||
import { mirror } from './utils';
|
import { mirror } from './utils';
|
||||||
|
|
||||||
@@ -8,4 +8,4 @@ export {
|
|||||||
MouseInteractions,
|
MouseInteractions,
|
||||||
ReplayerEvents,
|
ReplayerEvents,
|
||||||
} from './types';
|
} from './types';
|
||||||
export { record, Replayer, mirror };
|
export { record, addCustomEvent, Replayer, mirror };
|
||||||
|
|||||||
@@ -25,6 +25,21 @@ function wrapEvent(e: event): eventWithTime {
|
|||||||
|
|
||||||
let wrappedEmit!: (e: eventWithTime, isCheckout?: boolean) => void;
|
let wrappedEmit!: (e: eventWithTime, isCheckout?: boolean) => void;
|
||||||
|
|
||||||
|
export function addCustomEvent<T>(tag: string, payload: T) {
|
||||||
|
if (!wrappedEmit) {
|
||||||
|
throw new Error('please add custom event after start recording');
|
||||||
|
}
|
||||||
|
wrappedEmit(
|
||||||
|
wrapEvent({
|
||||||
|
type: EventType.Custom,
|
||||||
|
data: {
|
||||||
|
tag,
|
||||||
|
payload,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function record(options: recordOptions = {}): listenerHandler | undefined {
|
function record(options: recordOptions = {}): listenerHandler | undefined {
|
||||||
const {
|
const {
|
||||||
emit,
|
emit,
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ interface ISuite extends Suite {
|
|||||||
interface IWindow extends Window {
|
interface IWindow extends Window {
|
||||||
rrweb: {
|
rrweb: {
|
||||||
record: (options: recordOptions) => listenerHandler | undefined;
|
record: (options: recordOptions) => listenerHandler | undefined;
|
||||||
|
addCustomEvent<T>(tag: string, payload: T): void;
|
||||||
};
|
};
|
||||||
emit: (e: eventWithTime) => undefined;
|
emit: (e: eventWithTime) => undefined;
|
||||||
}
|
}
|
||||||
@@ -180,4 +181,19 @@ describe('record', function(this: ISuite) {
|
|||||||
await this.page.waitFor(50);
|
await this.page.waitFor(50);
|
||||||
assertSnapshot(this.events, __filename, 'async-checkout');
|
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');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
4
typings/index.d.ts
vendored
4
typings/index.d.ts
vendored
@@ -1,5 +1,5 @@
|
|||||||
import record from './record';
|
import record, { addCustomEvent } from './record';
|
||||||
import { Replayer } from './replay';
|
import { Replayer } from './replay';
|
||||||
import { mirror } from './utils';
|
import { mirror } from './utils';
|
||||||
export { EventType, IncrementalSource, MouseInteractions, ReplayerEvents, } from './types';
|
export { EventType, IncrementalSource, MouseInteractions, ReplayerEvents, } from './types';
|
||||||
export { record, Replayer, mirror };
|
export { record, addCustomEvent, Replayer, mirror };
|
||||||
|
|||||||
1
typings/record/index.d.ts
vendored
1
typings/record/index.d.ts
vendored
@@ -1,3 +1,4 @@
|
|||||||
import { recordOptions, listenerHandler } from '../types';
|
import { recordOptions, listenerHandler } from '../types';
|
||||||
|
export declare function addCustomEvent<T>(tag: string, payload: T): void;
|
||||||
declare function record(options?: recordOptions): listenerHandler | undefined;
|
declare function record(options?: recordOptions): listenerHandler | undefined;
|
||||||
export default record;
|
export default record;
|
||||||
|
|||||||
Reference in New Issue
Block a user