diff --git a/src/index.ts b/src/index.ts index 2aa2e0ad..7883678d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ import record from './record'; import { Replayer } from './replay'; import { mirror } from './utils'; +import * as utils from './utils'; export { EventType, @@ -11,4 +12,4 @@ export { const { addCustomEvent } = record; -export { record, addCustomEvent, Replayer, mirror }; +export { record, addCustomEvent, Replayer, mirror, utils }; diff --git a/src/record/observer.ts b/src/record/observer.ts index 9d65ebdf..55fe3b1c 100644 --- a/src/record/observer.ts +++ b/src/record/observer.ts @@ -181,8 +181,8 @@ function initViewportResizeObserver( return on('resize', updateDimension, window); } -const INPUT_TAGS = ['INPUT', 'TEXTAREA', 'SELECT']; -const MASK_TYPES = [ +export const INPUT_TAGS = ['INPUT', 'TEXTAREA', 'SELECT']; +export const MASK_TYPES = [ 'color', 'date', 'datetime-local', diff --git a/src/replay/index.ts b/src/replay/index.ts index 84cba123..c62a6d4a 100644 --- a/src/replay/index.ts +++ b/src/replay/index.ts @@ -1,4 +1,4 @@ -import { rebuild, buildNodeWithSN, idNodeMap } from 'rrweb-snapshot'; +import { rebuild, buildNodeWithSN } from 'rrweb-snapshot'; import * as mittProxy from 'mitt'; import * as smoothscroll from 'smoothscroll-polyfill'; import { Timer } from './timer'; diff --git a/src/utils.ts b/src/utils.ts index 2ee32c2f..b83a74e0 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -34,7 +34,7 @@ export const mirror: Mirror = { const id = n.__sn && n.__sn.id; delete mirror.map[id]; if (n.childNodes) { - n.childNodes.forEach(child => + n.childNodes.forEach((child) => mirror.removeNodeFromMap((child as Node) as INode), ); } @@ -53,7 +53,7 @@ export function throttle( let timeout: number | null = null; let previous = 0; // tslint:disable-next-line: only-arrow-functions - return function(arg: T) { + return function (arg: T) { let now = Date.now(); if (!previous && options.leading === false) { previous = now; @@ -83,9 +83,10 @@ export function hookSetter( key: string | number | symbol, d: PropertyDescriptor, isRevoked?: boolean, + win = window, ): hookResetter { - const original = Object.getOwnPropertyDescriptor(target, key); - Object.defineProperty( + const original = win.Object.getOwnPropertyDescriptor(target, key); + win.Object.defineProperty( target, key, isRevoked @@ -130,7 +131,7 @@ export function isBlocked(node: Node | null, blockClass: blockClass): boolean { if (typeof blockClass === 'string') { needBlock = (node as HTMLElement).classList.contains(blockClass); } else { - (node as HTMLElement).classList.forEach(className => { + (node as HTMLElement).classList.forEach((className) => { if (blockClass.test(className)) { needBlock = true; } diff --git a/typings/index.d.ts b/typings/index.d.ts index 2a3d0900..09491491 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1,6 +1,7 @@ import record from './record'; import { Replayer } from './replay'; import { mirror } from './utils'; +import * as utils from './utils'; export { EventType, IncrementalSource, MouseInteractions, ReplayerEvents, } from './types'; declare const addCustomEvent: (tag: string, payload: T) => void; -export { record, addCustomEvent, Replayer, mirror }; +export { record, addCustomEvent, Replayer, mirror, utils }; diff --git a/typings/record/observer.d.ts b/typings/record/observer.d.ts index 4c67f319..703605fb 100644 --- a/typings/record/observer.d.ts +++ b/typings/record/observer.d.ts @@ -1,2 +1,4 @@ import { observerParam, listenerHandler, hooksParam } from '../types'; +export declare const INPUT_TAGS: string[]; +export declare const MASK_TYPES: string[]; export default function initObservers(o: observerParam, hooks?: hooksParam): listenerHandler; diff --git a/typings/utils.d.ts b/typings/utils.d.ts index 7b3323b7..32c62f84 100644 --- a/typings/utils.d.ts +++ b/typings/utils.d.ts @@ -3,7 +3,7 @@ import { INode } from 'rrweb-snapshot'; export declare function on(type: string, fn: EventListenerOrEventListenerObject, target?: Document | Window): listenerHandler; export declare const mirror: Mirror; export declare function throttle(func: (arg: T) => void, wait: number, options?: throttleOptions): (arg: T) => void; -export declare function hookSetter(target: T, key: string | number | symbol, d: PropertyDescriptor, isRevoked?: boolean): hookResetter; +export declare function hookSetter(target: T, key: string | number | symbol, d: PropertyDescriptor, isRevoked?: boolean, win?: Window & typeof globalThis): hookResetter; export declare function getWindowHeight(): number; export declare function getWindowWidth(): number; export declare function isBlocked(node: Node | null, blockClass: blockClass): boolean;