From 38e251c9a70542c1a97898a8a2499f7b4f627289 Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Fri, 12 Jul 2024 15:26:12 +0100 Subject: [PATCH] Record: Export a version of `isBlocked` that can be used without providing config if recording has already started --- packages/record/src/index.ts | 39 ++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/packages/record/src/index.ts b/packages/record/src/index.ts index c2820aa1d2..e91634c12b 100644 --- a/packages/record/src/index.ts +++ b/packages/record/src/index.ts @@ -1,3 +1,38 @@ -import { record } from 'rrweb'; +import { record as rrwebRecord, type recordOptions } from 'rrweb'; +import { type listenerHandler, type eventWithTime } from '@rrweb/types'; -export { record }; +let currentOptions: recordOptions | null = null; + +function record( + options: recordOptions = {}, +): listenerHandler | undefined { + // save what options were used + currentOptions = options; + return rrwebRecord(options); +} + +/* + * a public version of utils.isBlocked which can be used to check a node after a recording is started + */ +function isBlocked( + node: Node, + options?: recordOptions, +): boolean { + if (options === undefined) { + if (currentOptions === null) { + throw new Error( + 'Either call after rrweb.record, or else pass in your recording config as the second argument', + ); + } else { + options = currentOptions; + } + } + return utils.isBlocked( + node, + options.blockClass || 'rr-block', + options.blockSelector || null, + true, + ); +} + +export { record, isBlocked };