Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions packages/rrweb/src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ function record<T = eventWithTime>(
userTriggeredOnInput = false,
collectFonts = false,
inlineImages = false,
plugins,
keepIframeSrcFn = () => false,
ignoreCSSAttributes = new Set([]),
errorHandler,
Expand Down Expand Up @@ -197,7 +198,11 @@ function record<T = eventWithTime>(
let incrementalSnapshotCount = 0;

const eventProcessor = (e: eventWithTime): T => {
// We ignore plugins here, as we do not have any
for (const plugin of plugins || []) {
if (plugin.eventProcessor) {
e = plugin.eventProcessor(e);
}
}
Comment on lines +201 to +205
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used

if (
packFn &&
// Disable packing events which will be emitted to parent frames.
Expand Down Expand Up @@ -319,8 +324,16 @@ function record<T = eventWithTime>(

/**
* Exposes mirror to the plugins
* We ignore plugins here, as we don't use any
*/
for (const plugin of plugins || []) {
if (plugin.getMirror)
plugin.getMirror({
nodeMirror: mirror,
crossOriginIframeMirror: iframeManager.crossOriginIframeMirror,
crossOriginIframeStyleMirror:
iframeManager.crossOriginIframeStyleMirror,
});
}
Comment on lines +328 to +336
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used


const processedNodeManager = new ProcessedNodeManager();

Expand Down Expand Up @@ -598,7 +611,23 @@ function record<T = eventWithTime>(
processedNodeManager,
canvasManager,
ignoreCSSAttributes,
plugins: [],
plugins:
plugins
?.filter((p) => p.observer)
?.map((p) => ({
observer: p.observer!,
options: p.options,
callback: (payload: object) =>
wrappedEmit(
wrapEvent({
type: EventType.Plugin,
data: {
plugin: p.name,
payload,
},
}),
),
})) || [],
Comment on lines +614 to +630
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably remove this

},
{},
);
Expand Down
8 changes: 7 additions & 1 deletion packages/rrweb/src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,12 @@ export function initObservers(
const customElementObserver = initCustomElementObserver(o);

// plugins
// we ignore plugins here, as we don't have any
const pluginHandlers: listenerHandler[] = [];
for (const plugin of o.plugins) {
pluginHandlers.push(
plugin.observer(plugin.callback, currentWindow, plugin.options),
);
}
Comment on lines +1318 to +1323
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used


return callbackWrapper(() => {
mutationBuffers.forEach((b) => b.reset());
Expand All @@ -1332,6 +1337,7 @@ export function initObservers(
fontObserver();
selectionObserver();
customElementObserver();
pluginHandlers.forEach((h) => h());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used

});
}

Expand Down
47 changes: 39 additions & 8 deletions packages/rrweb/src/replay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,10 @@ export class Replayer {

/**
* Exposes mirror to the plugins
* We ignore plugins here, as we don't have any
*/
for (const plugin of this.config.plugins || []) {
if (plugin.getMirror) plugin.getMirror({ nodeMirror: this.mirror });
}

this.emitter.on(ReplayerEvents.Flush, () => {
if (this.usingVirtualDom) {
Expand Down Expand Up @@ -234,7 +236,11 @@ export class Replayer {
else if (data.source === IncrementalSource.StyleDeclaration)
this.applyStyleDeclaration(data, styleSheet);
},
// we ignore plugins here, as we don't have any
afterAppend: (node: Node, id: number) => {
for (const plugin of this.config.plugins || []) {
if (plugin.onBuild) plugin.onBuild(node, { id, replayer: this });
}
},
};
if (this.iframe.contentDocument)
try {
Expand Down Expand Up @@ -717,7 +723,9 @@ export class Replayer {
castFn();
}

// we ignore plugins here, as we don't have any
for (const plugin of this.config.plugins || []) {
if (plugin.handler) plugin.handler(event, isSync, { replayer: this });
}

this.service.send({ type: 'CAST_EVENT', payload: { event } });

Expand Down Expand Up @@ -770,7 +778,13 @@ export class Replayer {
const collected: AppendedIframe[] = [];
const afterAppend = (builtNode: Node, id: number) => {
this.collectIframeAndAttachDocument(collected, builtNode);
// we ignore plugins here, as we don't have any
for (const plugin of this.config.plugins || []) {
if (plugin.onBuild)
plugin.onBuild(builtNode, {
id,
replayer: this,
});
}
};

/**
Expand Down Expand Up @@ -863,7 +877,7 @@ export class Replayer {
type TMirror = typeof mirror extends Mirror ? Mirror : RRDOMMirror;

const collected: AppendedIframe[] = [];
const afterAppend = (builtNode: Node, _id: number) => {
const afterAppend = (builtNode: Node, id: number) => {
this.collectIframeAndAttachDocument(collected, builtNode);
const sn = (mirror as TMirror).getMeta(builtNode as unknown as TNode);
if (
Expand All @@ -878,7 +892,14 @@ export class Replayer {
}

// Skip the plugin onBuild callback in the virtual dom mode
// we ignore plugins here, as we don't have any
if (this.usingVirtualDom) return;
for (const plugin of this.config.plugins || []) {
if (plugin.onBuild)
plugin.onBuild(builtNode, {
id,
replayer: this,
});
}
};

buildNodeWithSN(mutation.node, {
Expand Down Expand Up @@ -1498,7 +1519,13 @@ export class Replayer {
);
return;
}
// we ignore plugins here, as we don't have any
const afterAppend = (node: Node | RRNode, id: number) => {
// Skip the plugin onBuild callback for virtual dom
if (this.usingVirtualDom) return;
for (const plugin of this.config.plugins || []) {
if (plugin.onBuild) plugin.onBuild(node, { id, replayer: this });
}
};

const target = buildNodeWithSN(mutation.node, {
doc: targetDoc as Document, // can be Document or RRDocument
Expand All @@ -1510,6 +1537,7 @@ export class Replayer {
* caveat: `afterAppend` only gets called on child nodes of target
* we have to call it again below when this target was added to the DOM
*/
afterAppend,
}) as Node | RRNode;

// legacy data, we should not have -1 siblings any more
Expand Down Expand Up @@ -1584,7 +1612,10 @@ export class Replayer {
} else {
(parent as TNode).appendChild(target as TNode);
}
// we ignore plugins here, as we don't have any
/**
* target was added, execute plugin hooks
*/
afterAppend(target, mutation.node.id);

/**
* https://github.com/rrweb-io/rrweb/pull/887
Expand Down
Loading