rrweb icon indicating copy to clipboard operation
rrweb copied to clipboard

[Question] Are checkout events emitted in pairs, first meta, then full snapshot?

Open matux opened this issue 6 months ago • 0 comments

This is the behavior I'm experiencing right now with a similar set up as:

const eventsMatrix = [[]];

rrweb.record({
  emit(event, isCheckout) {
    // isCheckout is a flag to tell you the events has been checkout
    if (isCheckout) {
      eventsMatrix.push([]);
    }
    const lastEvents = eventsMatrix[eventsMatrix.length - 1];
    lastEvents.push(event);
  },
  checkoutEveryNms: 5 * 60 * 1000, // checkout every 5 minutes
});

So, after the 5 minutes, I'll get two consecutive events with isCheckout = true, the first one is a meta type event, the second is a full snapshot.

Which I find confusing because given your example, it would seem like there's only one isCheckout event every 5 minutes.

You can see in the console:

Recorder: checkout event {type: 4, data: {…}, timestamp: 1744936898033}data: {href: 'http://localhost:3001/', width: 1158, height: 1002}timestamp: 1744936898033type: 4[[Prototype]]: Object
Recorder: checkout event {type: 2, data: {…}, timestamp: 1744936898033}data: {node: {…}, initialOffset: {…}}timestamp: 1744936898033type: 2[[Prototype]]: Object

And the code is very simple:

    this.#stopFn = this.#recordFn({
      emit: (event, isCheckout) => {
        console.log(`Recorder: ${isCheckout ? 'checkout' : ''} event`, event);
        if (isCheckout) {
          this.#events.previous = this.#events.current;
          this.#events.current = [];
        }

        this.#events.current.push(event);
      },
      checkoutEveryNms: 300000, // 5 minutes
      ...this.options,
    });

But if this is the correct behavior, I'd need to adapt my code to expect two checkout events. Could someone clarify this for me?

Thank you so much, and thank you for all the hard work you put in this library.

matux avatar Apr 18 '25 01:04 matux