Skip to content

Commit

Permalink
fix: wrappedEmit is not a function (#1034)
Browse files Browse the repository at this point in the history
Co-authored-by: wangfukang <wangfukang@kuaishou.com>
  • Loading branch information
2 people authored and Vadman97 committed Nov 4, 2022
1 parent 35d49f0 commit ecf25b4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/rrweb/src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ let wrappedEmit!: (e: eventWithTime, isCheckout?: boolean) => void;

let takeFullSnapshot!: (isCheckout?: boolean) => void;
let canvasManager!: CanvasManager;
let recording = false;

const mirror = createMirror();
function record<T = eventWithTime>(
Expand Down Expand Up @@ -570,6 +571,7 @@ function record<T = eventWithTime>(
const init = () => {
takeFullSnapshot();
handlers.push(observe(document));
recording = true;
};
if (
document.readyState === 'interactive' ||
Expand All @@ -595,9 +597,7 @@ function record<T = eventWithTime>(
}
return () => {
handlers.forEach((h) => h());
// reset init fns when stopping record
(wrappedEmit as unknown) = undefined;
(takeFullSnapshot as unknown) = undefined;
recording = false;
};
} catch (error) {
// TODO: handle internal error
Expand All @@ -606,7 +606,7 @@ function record<T = eventWithTime>(
}

record.addCustomEvent = <T>(tag: string, payload: T) => {
if (!wrappedEmit) {
if (!recording) {
throw new Error('please add custom event after start recording');
}
wrappedEmit(
Expand All @@ -625,7 +625,7 @@ record.freezePage = () => {
};

record.takeFullSnapshot = (isCheckout?: boolean) => {
if (!takeFullSnapshot) {
if (!recording) {
throw new Error('please take full snapshot after start recording');
}
takeFullSnapshot(isCheckout);
Expand Down

0 comments on commit ecf25b4

Please sign in to comment.