init the repo and integrate rrweb-snapshot
This commit is contained in:
3
src/index.ts
Normal file
3
src/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import record from './record';
|
||||
|
||||
export { record };
|
||||
35
src/record.ts
Normal file
35
src/record.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { snapshot } from 'rrweb-snapshot';
|
||||
import { EventType, event } from './types';
|
||||
|
||||
function on(
|
||||
type: string,
|
||||
fn: EventListenerOrEventListenerObject,
|
||||
target = document,
|
||||
) {
|
||||
target.addEventListener(type, fn);
|
||||
}
|
||||
|
||||
function createEvent(type: EventType, data: any): event {
|
||||
return {
|
||||
type,
|
||||
data,
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
}
|
||||
|
||||
function emit(e: event) {}
|
||||
|
||||
function record() {
|
||||
on('DOMContentLoaded', () => {
|
||||
emit(
|
||||
createEvent(EventType.DomContentLoaded, { href: window.location.href }),
|
||||
);
|
||||
});
|
||||
on('load', () => {
|
||||
emit(createEvent(EventType.Load, null));
|
||||
const node = snapshot(document);
|
||||
emit(createEvent(EventType.FullSnapshot, { node }));
|
||||
});
|
||||
}
|
||||
|
||||
export default record;
|
||||
12
src/types.ts
Normal file
12
src/types.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export enum EventType {
|
||||
DomContentLoaded,
|
||||
Load,
|
||||
FullSnapshot,
|
||||
IncrementalSnapshot,
|
||||
}
|
||||
|
||||
export type event = {
|
||||
type: EventType;
|
||||
timestamp: number;
|
||||
data: any;
|
||||
};
|
||||
Reference in New Issue
Block a user