Skip to content

Commit 39aff97

Browse files
authored
Add rrweb event logging to console for debugging (#1173)
1 parent d71150a commit 39aff97

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/browser/replay/defaults.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
module.exports = {
66
enabled: false, // Whether recording is enabled
77
autoStart: true, // Start recording automatically when Rollbar initializes
8+
debug: {
9+
logEmits: false, // Whether to log emitted events
10+
},
811

912
// Recording options
1013
inlineStylesheet: true, // Whether to inline stylesheets to improve replay accuracy

src/browser/replay/recorder.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,18 @@ export default class Recorder {
140140

141141
this.#stopFn = this.#recordFn({
142142
emit: (event, isCheckout) => {
143+
if (this.options.debug?.logEmits) {
144+
this._logEvent(event, isCheckout);
145+
}
146+
143147
if (isCheckout) {
144148
this.#events.previous = this.#events.current;
145149
this.#events.current = [];
146150
}
147151

148152
this.#events.current.push(event);
149153
},
150-
checkoutEveryNms: 300000, // 5 minutes
154+
checkoutEveryNms: 5 * 60 * 1000, // 5 minutes
151155
...this.options,
152156
});
153157

@@ -178,4 +182,24 @@ export default class Recorder {
178182
current: [],
179183
};
180184
}
185+
186+
_logEvent(event, isCheckout) {
187+
console.log(
188+
`Recorder: ${isCheckout ? 'checkout' : ''} event\n`,
189+
((e) => {
190+
const seen = new WeakSet();
191+
return JSON.stringify(
192+
e,
193+
(_, v) => {
194+
if (typeof v === 'object' && v !== null) {
195+
if (seen.has(v)) return '[Circular]';
196+
seen.add(v);
197+
}
198+
return v;
199+
},
200+
2,
201+
);
202+
})(event),
203+
);
204+
}
181205
}

0 commit comments

Comments
 (0)