From 42ffd923d62cb3ba6e976ccc65e1cdf517991b98 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 27 Oct 2023 10:09:30 +0200 Subject: [PATCH] feat: Remove `plugins` related code, which is not used (#123) This allows us to remove some code in the codebase that we don't actually use, streamlining this a bit and saving some bytes. --- packages/rrweb/src/record/index.ts | 35 +-- packages/rrweb/src/record/observer.ts | 8 +- packages/rrweb/src/replay/index.ts | 47 +-- .../__snapshots__/integration.test.ts.snap | 288 ------------------ 4 files changed, 12 insertions(+), 366 deletions(-) diff --git a/packages/rrweb/src/record/index.ts b/packages/rrweb/src/record/index.ts index b74da44ce0..4a9b4064fc 100644 --- a/packages/rrweb/src/record/index.ts +++ b/packages/rrweb/src/record/index.ts @@ -109,7 +109,6 @@ function record( userTriggeredOnInput = false, collectFonts = false, inlineImages = false, - plugins, keepIframeSrcFn = () => false, ignoreCSSAttributes = new Set([]), errorHandler, @@ -197,11 +196,7 @@ function record( let incrementalSnapshotCount = 0; const eventProcessor = (e: eventWithTime): T => { - for (const plugin of plugins || []) { - if (plugin.eventProcessor) { - e = plugin.eventProcessor(e); - } - } + // We ignore plugins here, as we do not have any if ( packFn && // Disable packing events which will be emitted to parent frames. @@ -322,16 +317,8 @@ function record( /** * 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, - }); - } const processedNodeManager = new ProcessedNodeManager(); @@ -612,23 +599,7 @@ function record( processedNodeManager, canvasManager, ignoreCSSAttributes, - 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, - }, - }), - ), - })) || [], + plugins: [], }, hooks, ); diff --git a/packages/rrweb/src/record/observer.ts b/packages/rrweb/src/record/observer.ts index bddf82f97d..69d5f68195 100644 --- a/packages/rrweb/src/record/observer.ts +++ b/packages/rrweb/src/record/observer.ts @@ -1440,12 +1440,7 @@ export function initObservers( const customElementObserver = initCustomElementObserver(o); // plugins - const pluginHandlers: listenerHandler[] = []; - for (const plugin of o.plugins) { - pluginHandlers.push( - plugin.observer(plugin.callback, currentWindow, plugin.options), - ); - } + // we ignore plugins here, as we don't have any return callbackWrapper(() => { mutationBuffers.forEach((b) => b.reset()); @@ -1462,7 +1457,6 @@ export function initObservers( fontObserver(); selectionObserver(); customElementObserver(); - pluginHandlers.forEach((h) => h()); }); } diff --git a/packages/rrweb/src/replay/index.ts b/packages/rrweb/src/replay/index.ts index 856a14c782..8388b95b7f 100644 --- a/packages/rrweb/src/replay/index.ts +++ b/packages/rrweb/src/replay/index.ts @@ -202,10 +202,8 @@ 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) { @@ -236,11 +234,7 @@ export class Replayer { else if (data.source === IncrementalSource.StyleDeclaration) this.applyStyleDeclaration(data, styleSheet); }, - afterAppend: (node: Node, id: number) => { - for (const plugin of this.config.plugins || []) { - if (plugin.onBuild) plugin.onBuild(node, { id, replayer: this }); - } - }, + // we ignore plugins here, as we don't have any }; if (this.iframe.contentDocument) try { @@ -723,9 +717,7 @@ export class Replayer { castFn(); } - for (const plugin of this.config.plugins || []) { - if (plugin.handler) plugin.handler(event, isSync, { replayer: this }); - } + // we ignore plugins here, as we don't have any this.service.send({ type: 'CAST_EVENT', payload: { event } }); @@ -778,13 +770,7 @@ export class Replayer { const collected: AppendedIframe[] = []; const afterAppend = (builtNode: Node, id: number) => { this.collectIframeAndAttachDocument(collected, builtNode); - for (const plugin of this.config.plugins || []) { - if (plugin.onBuild) - plugin.onBuild(builtNode, { - id, - replayer: this, - }); - } + // we ignore plugins here, as we don't have any }; /** @@ -877,7 +863,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 ( @@ -892,14 +878,7 @@ export class Replayer { } // Skip the plugin onBuild callback in the virtual dom mode - if (this.usingVirtualDom) return; - for (const plugin of this.config.plugins || []) { - if (plugin.onBuild) - plugin.onBuild(builtNode, { - id, - replayer: this, - }); - } + // we ignore plugins here, as we don't have any }; buildNodeWithSN(mutation.node, { @@ -1519,13 +1498,7 @@ export class Replayer { ); return; } - 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 }); - } - }; + // we ignore plugins here, as we don't have any const target = buildNodeWithSN(mutation.node, { doc: targetDoc as Document, // can be Document or RRDocument @@ -1537,7 +1510,6 @@ 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 @@ -1612,10 +1584,7 @@ export class Replayer { } else { (parent as TNode).appendChild(target as TNode); } - /** - * target was added, execute plugin hooks - */ - afterAppend(target, mutation.node.id); + // we ignore plugins here, as we don't have any /** * https://github.com/rrweb-io/rrweb/pull/887 diff --git a/packages/rrweb/test/__snapshots__/integration.test.ts.snap b/packages/rrweb/test/__snapshots__/integration.test.ts.snap index 79919c964f..1a39571f45 100644 --- a/packages/rrweb/test/__snapshots__/integration.test.ts.snap +++ b/packages/rrweb/test/__snapshots__/integration.test.ts.snap @@ -7887,22 +7887,6 @@ exports[`record integration tests should handle recursive console messages 1`] = \\"top\\": 0 } } - }, - { - \\"type\\": 6, - \\"data\\": { - \\"plugin\\": \\"rrweb/console@1\\", - \\"payload\\": { - \\"level\\": \\"log\\", - \\"trace\\": [ - \\"__puppeteer_evaluation_script__:20:21\\" - ], - \\"payload\\": [ - \\"\\\\\\"Proxied object:\\\\\\"\\", - \\"\\\\\\"[object Object]\\\\\\"\\" - ] - } - } } ]" `; @@ -15452,265 +15436,6 @@ exports[`record integration tests should record console messages 1`] = ` } } }, - { - \\"type\\": 6, - \\"data\\": { - \\"plugin\\": \\"rrweb/console@1\\", - \\"payload\\": { - \\"level\\": \\"assert\\", - \\"trace\\": [ - \\"__puppeteer_evaluation_script__:2:21\\" - ], - \\"payload\\": [ - \\"true\\", - \\"\\\\\\"assert\\\\\\"\\" - ] - } - } - }, - { - \\"type\\": 6, - \\"data\\": { - \\"plugin\\": \\"rrweb/console@1\\", - \\"payload\\": { - \\"level\\": \\"count\\", - \\"trace\\": [ - \\"__puppeteer_evaluation_script__:3:21\\" - ], - \\"payload\\": [ - \\"\\\\\\"count\\\\\\"\\" - ] - } - } - }, - { - \\"type\\": 6, - \\"data\\": { - \\"plugin\\": \\"rrweb/console@1\\", - \\"payload\\": { - \\"level\\": \\"countReset\\", - \\"trace\\": [ - \\"__puppeteer_evaluation_script__:4:21\\" - ], - \\"payload\\": [ - \\"\\\\\\"count\\\\\\"\\" - ] - } - } - }, - { - \\"type\\": 6, - \\"data\\": { - \\"plugin\\": \\"rrweb/console@1\\", - \\"payload\\": { - \\"level\\": \\"debug\\", - \\"trace\\": [ - \\"__puppeteer_evaluation_script__:5:21\\" - ], - \\"payload\\": [ - \\"\\\\\\"debug\\\\\\"\\" - ] - } - } - }, - { - \\"type\\": 6, - \\"data\\": { - \\"plugin\\": \\"rrweb/console@1\\", - \\"payload\\": { - \\"level\\": \\"dir\\", - \\"trace\\": [ - \\"__puppeteer_evaluation_script__:6:21\\" - ], - \\"payload\\": [ - \\"\\\\\\"dir\\\\\\"\\" - ] - } - } - }, - { - \\"type\\": 6, - \\"data\\": { - \\"plugin\\": \\"rrweb/console@1\\", - \\"payload\\": { - \\"level\\": \\"dirxml\\", - \\"trace\\": [ - \\"__puppeteer_evaluation_script__:7:21\\" - ], - \\"payload\\": [ - \\"\\\\\\"dirxml\\\\\\"\\" - ] - } - } - }, - { - \\"type\\": 6, - \\"data\\": { - \\"plugin\\": \\"rrweb/console@1\\", - \\"payload\\": { - \\"level\\": \\"group\\", - \\"trace\\": [ - \\"__puppeteer_evaluation_script__:8:21\\" - ], - \\"payload\\": [] - } - } - }, - { - \\"type\\": 6, - \\"data\\": { - \\"plugin\\": \\"rrweb/console@1\\", - \\"payload\\": { - \\"level\\": \\"groupCollapsed\\", - \\"trace\\": [ - \\"__puppeteer_evaluation_script__:9:21\\" - ], - \\"payload\\": [] - } - } - }, - { - \\"type\\": 6, - \\"data\\": { - \\"plugin\\": \\"rrweb/console@1\\", - \\"payload\\": { - \\"level\\": \\"info\\", - \\"trace\\": [ - \\"__puppeteer_evaluation_script__:10:21\\" - ], - \\"payload\\": [ - \\"\\\\\\"info\\\\\\"\\" - ] - } - } - }, - { - \\"type\\": 6, - \\"data\\": { - \\"plugin\\": \\"rrweb/console@1\\", - \\"payload\\": { - \\"level\\": \\"log\\", - \\"trace\\": [ - \\"__puppeteer_evaluation_script__:11:21\\" - ], - \\"payload\\": [ - \\"\\\\\\"log\\\\\\"\\" - ] - } - } - }, - { - \\"type\\": 6, - \\"data\\": { - \\"plugin\\": \\"rrweb/console@1\\", - \\"payload\\": { - \\"level\\": \\"table\\", - \\"trace\\": [ - \\"__puppeteer_evaluation_script__:12:21\\" - ], - \\"payload\\": [ - \\"\\\\\\"table\\\\\\"\\" - ] - } - } - }, - { - \\"type\\": 6, - \\"data\\": { - \\"plugin\\": \\"rrweb/console@1\\", - \\"payload\\": { - \\"level\\": \\"time\\", - \\"trace\\": [ - \\"__puppeteer_evaluation_script__:13:21\\" - ], - \\"payload\\": [] - } - } - }, - { - \\"type\\": 6, - \\"data\\": { - \\"plugin\\": \\"rrweb/console@1\\", - \\"payload\\": { - \\"level\\": \\"timeEnd\\", - \\"trace\\": [ - \\"__puppeteer_evaluation_script__:14:21\\" - ], - \\"payload\\": [] - } - } - }, - { - \\"type\\": 6, - \\"data\\": { - \\"plugin\\": \\"rrweb/console@1\\", - \\"payload\\": { - \\"level\\": \\"timeLog\\", - \\"trace\\": [ - \\"__puppeteer_evaluation_script__:15:21\\" - ], - \\"payload\\": [] - } - } - }, - { - \\"type\\": 6, - \\"data\\": { - \\"plugin\\": \\"rrweb/console@1\\", - \\"payload\\": { - \\"level\\": \\"trace\\", - \\"trace\\": [ - \\"__puppeteer_evaluation_script__:16:21\\" - ], - \\"payload\\": [ - \\"\\\\\\"trace\\\\\\"\\" - ] - } - } - }, - { - \\"type\\": 6, - \\"data\\": { - \\"plugin\\": \\"rrweb/console@1\\", - \\"payload\\": { - \\"level\\": \\"warn\\", - \\"trace\\": [ - \\"__puppeteer_evaluation_script__:17:21\\" - ], - \\"payload\\": [ - \\"\\\\\\"warn\\\\\\"\\" - ] - } - } - }, - { - \\"type\\": 6, - \\"data\\": { - \\"plugin\\": \\"rrweb/console@1\\", - \\"payload\\": { - \\"level\\": \\"clear\\", - \\"trace\\": [ - \\"__puppeteer_evaluation_script__:18:21\\" - ], - \\"payload\\": [] - } - } - }, - { - \\"type\\": 6, - \\"data\\": { - \\"plugin\\": \\"rrweb/console@1\\", - \\"payload\\": { - \\"level\\": \\"log\\", - \\"trace\\": [ - \\"__puppeteer_evaluation_script__:19:21\\" - ], - \\"payload\\": [ - \\"\\\\\\"TypeError: a message\\\\\\\\n at __puppeteer_evaluation_script__:19:25\\\\\\\\nEnd of stack for Error object\\\\\\"\\" - ] - } - } - }, { \\"type\\": 3, \\"data\\": { @@ -15780,19 +15505,6 @@ exports[`record integration tests should record console messages 1`] = ` \\"attributes\\": [], \\"isAttachIframe\\": true } - }, - { - \\"type\\": 6, - \\"data\\": { - \\"plugin\\": \\"rrweb/console@1\\", - \\"payload\\": { - \\"level\\": \\"log\\", - \\"trace\\": [], - \\"payload\\": [ - \\"\\\\\\"from iframe\\\\\\"\\" - ] - } - } } ]" `;