improve record method and bump 0.2.0
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "rrweb",
|
"name": "rrweb",
|
||||||
"version": "0.1.0",
|
"version": "0.2.0",
|
||||||
"description": "record and replay the web",
|
"description": "record and replay the web",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ function wrapEvent(e: event): eventWithTime {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function record(options: recordOptions) {
|
function record(options: recordOptions = {}) {
|
||||||
try {
|
|
||||||
const { emit } = options;
|
const { emit } = options;
|
||||||
// runtime checks for user options
|
// runtime checks for user options
|
||||||
if (!emit) {
|
if (!emit) {
|
||||||
throw new Error('emit function is required');
|
throw new Error('emit function is required');
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
on('DOMContentLoaded', () => {
|
on('DOMContentLoaded', () => {
|
||||||
emit(
|
emit(
|
||||||
wrapEvent({
|
wrapEvent({
|
||||||
@@ -33,7 +33,9 @@ function record(options: recordOptions) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
on('load', () => {
|
on(
|
||||||
|
'load',
|
||||||
|
() => {
|
||||||
emit(wrapEvent({ type: EventType.Load, data: {} }));
|
emit(wrapEvent({ type: EventType.Load, data: {} }));
|
||||||
const [node, idNodeMap] = snapshot(document);
|
const [node, idNodeMap] = snapshot(document);
|
||||||
if (!node) {
|
if (!node) {
|
||||||
@@ -103,9 +105,12 @@ function record(options: recordOptions) {
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
|
window,
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// TODO: handle internal error
|
// TODO: handle internal error
|
||||||
|
console.warn(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ export type eventWithTime = event & {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type recordOptions = {
|
export type recordOptions = {
|
||||||
emit: (e: eventWithTime) => void;
|
emit?: (e: eventWithTime) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type observerParam = {
|
export type observerParam = {
|
||||||
|
|||||||
Reference in New Issue
Block a user