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
wfk007 and wfk007 authored Nov 1, 2022
1 parent bdd8940 commit 5012b1e
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 @@ -42,6 +42,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 @@ -535,6 +536,7 @@ function record<T = eventWithTime>(
const init = () => {
takeFullSnapshot();
handlers.push(observe(document));
recording = true;
};
if (
document.readyState === 'interactive' ||
Expand All @@ -560,9 +562,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 @@ -571,7 +571,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 @@ -590,7 +590,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 5012b1e

Please sign in to comment.