-
Notifications
You must be signed in to change notification settings - Fork 7.1k
feat: enable console log recording in session replays #4267
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,29 +16,33 @@ export function ReplayPlayer({ events }: { events: any[] }) { | |
| useEffect(() => { | ||
| if (!containerRef.current || !events?.length) return; | ||
|
|
||
| import('rrweb-player').then(mod => { | ||
| const RRWebPlayer = mod.default; | ||
| Promise.all([import('rrweb-player'), import('@rrweb/rrweb-plugin-console-replay')]).then( | ||
| ([mod, consoleMod]) => { | ||
| const RRWebPlayer = mod.default; | ||
| const { getReplayConsolePlugin } = consoleMod; | ||
|
|
||
| if (containerRef.current) { | ||
| containerRef.current.innerHTML = ''; | ||
| } | ||
| if (containerRef.current) { | ||
| containerRef.current.innerHTML = ''; | ||
| } | ||
|
|
||
| playerRef.current = new RRWebPlayer({ | ||
| target: containerRef.current, | ||
| props: { | ||
| events: events, | ||
| width: playerWidth, | ||
| height: playerHeight, | ||
| autoPlay: false, | ||
| showController: true, | ||
| speedOption: [1, 2, 4, 8], | ||
| useVirtualDom: false, | ||
| showWarning: false, | ||
| }, | ||
| }); | ||
| playerRef.current = new RRWebPlayer({ | ||
| target: containerRef.current, | ||
| props: { | ||
| events: events, | ||
| width: playerWidth, | ||
| height: playerHeight, | ||
| autoPlay: false, | ||
| showController: true, | ||
| speedOption: [1, 2, 4, 8], | ||
| useVirtualDom: false, | ||
| showWarning: false, | ||
| plugins: [getReplayConsolePlugin()], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| }, | ||
| }); | ||
|
|
||
| setLoaded(true); | ||
| }); | ||
| setLoaded(true); | ||
| }, | ||
| ); | ||
|
|
||
| return () => { | ||
| if (playerRef.current) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,7 @@ interface ReplayConfig { | |||||
| maskLevel?: string; | ||||||
| maxDuration?: number; | ||||||
| blockSelector?: string; | ||||||
| recordConsole?: boolean; | ||||||
| } | ||||||
|
|
||||||
| export function WebsiteReplaySettings({ websiteId }: { websiteId: string }) { | ||||||
|
|
@@ -37,13 +38,15 @@ export function WebsiteReplaySettings({ websiteId }: { websiteId: string }) { | |||||
| const [maskLevel, setMaskLevel] = useState(config.maskLevel ?? 'moderate'); | ||||||
| const [maxDuration, setMaxDuration] = useState(String(config.maxDuration ?? 300000)); | ||||||
| const [blockSelector, setBlockSelector] = useState(config.blockSelector ?? ''); | ||||||
| const [recordConsole, setRecordConsole] = useState(config.recordConsole ?? false); | ||||||
|
|
||||||
| const recorderUrl = cloudMode | ||||||
| ? `${process.env.cloudUrl}/${RECORDER_NAME}` | ||||||
| : `${window?.location?.origin || ''}${process.env.basePath || ''}/${RECORDER_NAME}`; | ||||||
|
|
||||||
| let recorderAttrs = `data-website-id="${websiteId}" data-sample-rate="${sampleRate}" data-mask-level="${maskLevel}" data-max-duration="${parseInt(maxDuration, 10) || 300000}"`; | ||||||
| if (blockSelector) recorderAttrs += ` data-block-selector="${blockSelector}"`; | ||||||
| if (recordConsole) recorderAttrs += ` data-record-console="true"`; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| const recorderCode = `<script defer src="${recorderUrl}" ${recorderAttrs}></script>`; | ||||||
|
|
||||||
| const handleToggle = async (value: boolean) => { | ||||||
|
|
@@ -77,6 +80,7 @@ export function WebsiteReplaySettings({ websiteId }: { websiteId: string }) { | |||||
| maskLevel, | ||||||
| maxDuration: parseInt(maxDuration, 10) || 300000, | ||||||
| ...(blockSelector && { blockSelector }), | ||||||
| recordConsole, | ||||||
| }, | ||||||
| }, | ||||||
| { | ||||||
|
|
@@ -151,6 +155,9 @@ export function WebsiteReplaySettings({ websiteId }: { websiteId: string }) { | |||||
| <Label>{t(labels.blockSelector)}</Label> | ||||||
| <TextField value={blockSelector} onChange={setBlockSelector} /> | ||||||
| </Column> | ||||||
| <Switch isSelected={recordConsole} onChange={setRecordConsole}> | ||||||
| {t(labels.recordConsole)} | ||||||
| </Switch> | ||||||
| <Row> | ||||||
| <Button variant="primary" onPress={handleSave} isDisabled={isPending}> | ||||||
| {t(labels.save)} | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { record } from 'rrweb'; | ||
| import { getRecordConsolePlugin } from '@rrweb/rrweb-plugin-console-record'; | ||
|
|
||
| (window => { | ||
| const { document } = window; | ||
|
|
@@ -15,6 +16,7 @@ import { record } from 'rrweb'; | |
| const maskLevel = config(`mask-level`) || 'moderate'; | ||
| const maxDuration = parseInt(config(`max-duration`) || '300000', 10); | ||
| const blockSelector = config(`block-selector`) || ''; | ||
| const recordConsole = config(`record-console`) === 'true'; | ||
|
|
||
| if (!website) return; | ||
|
|
||
|
|
@@ -114,6 +116,12 @@ import { record } from 'rrweb'; | |
|
|
||
| const maskConfig = getMaskConfig(maskLevel); | ||
|
|
||
| const plugins = []; | ||
|
|
||
| if (recordConsole) { | ||
| plugins.push(getRecordConsolePlugin()); | ||
| } | ||
|
Comment on lines
+121
to
+123
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| stopFn = record({ | ||
| emit(event) { | ||
| if (stopped) return; | ||
|
|
@@ -132,6 +140,7 @@ import { record } from 'rrweb'; | |
| scheduleFlush(); | ||
| }, | ||
| ...maskConfig, | ||
| plugins, | ||
| inlineStylesheet: true, | ||
| slimDOMOptions: { | ||
| script: true, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rrweb-playerwas bumped from1.0.0-alpha.4to2.0.0-alpha.20— a major-version change across 16 alpha releases. The lock file confirms the new package no longer directly listsrrwebas a dependency; it now pulls in@rrweb/packerand@rrweb/replayinstead, indicating significant internal restructuring. Bundling this breaking upgrade with the console-log feature makes it harder to bisect regressions if existing replays stop playing correctly.