Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrappedEmit is not a function #1034

Merged
merged 1 commit into from
Nov 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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