From 5012b1eb601915a386c14045ef7cab66357413ad Mon Sep 17 00:00:00 2001 From: fukang wang Date: Tue, 1 Nov 2022 08:27:30 +0800 Subject: [PATCH] fix: wrappedEmit is not a function (#1034) Co-authored-by: wangfukang --- packages/rrweb/src/record/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/rrweb/src/record/index.ts b/packages/rrweb/src/record/index.ts index 26e07fc8..954ec458 100644 --- a/packages/rrweb/src/record/index.ts +++ b/packages/rrweb/src/record/index.ts @@ -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( @@ -535,6 +536,7 @@ function record( const init = () => { takeFullSnapshot(); handlers.push(observe(document)); + recording = true; }; if ( document.readyState === 'interactive' || @@ -560,9 +562,7 @@ function record( } 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 @@ -571,7 +571,7 @@ function record( } record.addCustomEvent = (tag: string, payload: T) => { - if (!wrappedEmit) { + if (!recording) { throw new Error('please add custom event after start recording'); } wrappedEmit( @@ -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);