Keep only last 200-400 events
See original GitHub issueI’m trying to keep only last 200-400 events but I can’t use the checkout feature as I’m using rrweb inside of an extension. The problem with extension is that DOM related events are to be run in the content_scripts
context, which re-runs after every page refresh or navigation. This. causes the new record()
to be called and run again causing the checkout to also reset. I’m maintaining the count outside of content_scripts
where data can persist. What I do is hacky, I create my own snapshot event and attach it to each event passed to the DB layer and check if the count is 100 I insert a snapshot event before it. At times this works without any problems but breaks with a blank screen always sometime later or with certain websites. Do I also need something other than my snapshot event or is there any better way to keep only last 200-400 events and not break the replayer. Here’s my snapshot logic
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
You can think of full snapshot
type: EventType.FullSnapshot
ortype: 2
events as keyframes in video files. When choosing what events to purge it is safe to do so before a full snapshot event. Just make sure you keep the full snapshot event. Mutation events (type: 3) are going to use that full snapshot as their base.You might have to add on a meta event before that to include the page width/height but you can create those after the fact as well.
Some comments on your example code: Between the
setTimeout
and thedocument.dispatchEvent
I’m afraid your events might get saved in the wrong order. It might help to push everything to an array and create a worker function that manipulates and sends the events viadocument.dispatchEvent
. That way you can guarantee the events get sent in order. Personally I also wouldn’t change the timestamp if I where you. I’m afraid it can mess things up in the replay.It was throwing error, then I realized I’m on the wrong version. Bumped it and it’s working like charm. I guess that’s all I need. I’ll be closing this issue. Thanks a bunch , you saved my days ❤️