UNPKG

@sdc-monitor/demo

Version:

<div align="center"> <a href="#" target="_blank"> <img src="https://i.loli.net/2021/07/28/EvPwd4NjVH3tBfO.jpg" alt="mito-logo" height="90"> </a> <p>A Lightweight SDK For Monitor Web</p>

41 lines (38 loc) 1.24 kB
import { BrowserBreadcrumbTypes, BrowserEventTypes } from '@sdc-monitor/shared' import { htmlElementAsString, on, throttle, _global } from '@sdc-monitor/utils' import { BasePluginType } from '@sdc-monitor/types' import { BrowserClient } from '../browserClient' import { addBreadcrumbInBrowser } from '../utils' export interface DomCollectedType { // maybe will add doubleClick or other in the future category: 'click' data: Document } const domPlugin: BasePluginType<BrowserEventTypes, BrowserClient> = { name: BrowserEventTypes.DOM, monitor(notify) { if (!('document' in _global)) return const clickThrottle = throttle(notify, this.options.throttleDelayTime) on( _global.document, 'click', function () { clickThrottle(BrowserEventTypes.DOM, { category: 'click', data: this }) }, true ) }, transform(collectedData: DomCollectedType) { const htmlString = htmlElementAsString(collectedData.data.activeElement as HTMLElement) return htmlString }, consumer(transformedData: string) { if (transformedData) { addBreadcrumbInBrowser.call(this, transformedData, BrowserBreadcrumbTypes.CLICK) } } } export default domPlugin