content-security-toolkit 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -0
- package/README.md +171 -0
- package/dist/config/default-extensions-config.json +103 -0
- package/dist/core/ContentProtector.d.ts +63 -0
- package/dist/core/ContentProtector.js +279 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +2 -0
- package/dist/core/mediator/ContentProtectionMediator.d.ts +86 -0
- package/dist/core/mediator/ContentProtectionMediator.js +238 -0
- package/dist/core/mediator/eventDataTypes.d.ts +205 -0
- package/dist/core/mediator/eventDataTypes.js +23 -0
- package/dist/core/mediator/handlers/abstractEventHandler.d.ts +67 -0
- package/dist/core/mediator/handlers/abstractEventHandler.js +106 -0
- package/dist/core/mediator/handlers/baseEventHandler.d.ts +65 -0
- package/dist/core/mediator/handlers/baseEventHandler.js +99 -0
- package/dist/core/mediator/handlers/devToolsEventHandler.d.ts +9 -0
- package/dist/core/mediator/handlers/devToolsEventHandler.js +95 -0
- package/dist/core/mediator/handlers/eventHandlerRegistry.d.ts +9 -0
- package/dist/core/mediator/handlers/eventHandlerRegistry.js +34 -0
- package/dist/core/mediator/handlers/extensionEventHandlers.d.ts +40 -0
- package/dist/core/mediator/handlers/extensionEventHandlers.js +140 -0
- package/dist/core/mediator/handlers/iFrameEventHandlers.d.ts +27 -0
- package/dist/core/mediator/handlers/iFrameEventHandlers.js +93 -0
- package/dist/core/mediator/handlers/index.d.ts +9 -0
- package/dist/core/mediator/handlers/index.js +34 -0
- package/dist/core/mediator/handlers/screenShotEventHandlers.d.ts +34 -0
- package/dist/core/mediator/handlers/screenShotEventHandlers.js +111 -0
- package/dist/core/mediator/protection-event.d.ts +94 -0
- package/dist/core/mediator/protection-event.js +43 -0
- package/dist/core/mediator/types.d.ts +105 -0
- package/dist/core/mediator/types.js +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/strategies/AbstractStrategy.d.ts +152 -0
- package/dist/strategies/AbstractStrategy.js +296 -0
- package/dist/strategies/AbstractStrategy.mediator.d.ts +162 -0
- package/dist/strategies/AbstractStrategy.mediator.js +349 -0
- package/dist/strategies/ClipboardStrategy.d.ts +67 -0
- package/dist/strategies/ClipboardStrategy.js +291 -0
- package/dist/strategies/ContextMenuStrategy.d.ts +60 -0
- package/dist/strategies/ContextMenuStrategy.js +454 -0
- package/dist/strategies/DevToolsStrategy copy.d.ts +85 -0
- package/dist/strategies/DevToolsStrategy copy.js +362 -0
- package/dist/strategies/DevToolsStrategy-detectorManager.d.ts +70 -0
- package/dist/strategies/DevToolsStrategy-detectorManager.js +309 -0
- package/dist/strategies/DevToolsStrategy-simple.d.ts +75 -0
- package/dist/strategies/DevToolsStrategy-simple.js +366 -0
- package/dist/strategies/DevToolsStrategy.d.ts +55 -0
- package/dist/strategies/DevToolsStrategy.js +314 -0
- package/dist/strategies/ExtensionStrategy.d.ts +66 -0
- package/dist/strategies/ExtensionStrategy.js +486 -0
- package/dist/strategies/IFrameStrategy.d.ts +49 -0
- package/dist/strategies/IFrameStrategy.js +255 -0
- package/dist/strategies/KeyboardStrategy.d.ts +35 -0
- package/dist/strategies/KeyboardStrategy.js +130 -0
- package/dist/strategies/PrintStrategy.d.ts +47 -0
- package/dist/strategies/PrintStrategy.js +201 -0
- package/dist/strategies/ScreenshotStrategy.d.ts +90 -0
- package/dist/strategies/ScreenshotStrategy.js +488 -0
- package/dist/strategies/SelectionStrategy.d.ts +49 -0
- package/dist/strategies/SelectionStrategy.js +216 -0
- package/dist/strategies/StrategyRegistry.d.ts +133 -0
- package/dist/strategies/StrategyRegistry.js +379 -0
- package/dist/strategies/WatermarkStrategy.d.ts +47 -0
- package/dist/strategies/WatermarkStrategy.js +273 -0
- package/dist/strategies/index.d.ts +9 -0
- package/dist/strategies/index.js +10 -0
- package/dist/types/index.d.ts +271 -0
- package/dist/types/index.js +16 -0
- package/dist/utils/DOMObserver.d.ts +68 -0
- package/dist/utils/DOMObserver.js +134 -0
- package/dist/utils/base/LoggableComponent.d.ts +62 -0
- package/dist/utils/base/LoggableComponent.js +95 -0
- package/dist/utils/debuggerDetector/debuggerDetectionWorker.d.ts +6 -0
- package/dist/utils/debuggerDetector/debuggerDetectionWorker.js +24 -0
- package/dist/utils/debuggerDetector/debuggerDetector.d.ts +55 -0
- package/dist/utils/debuggerDetector/debuggerDetector.js +158 -0
- package/dist/utils/debuggerDetector/firefoxDetector.d.ts +8 -0
- package/dist/utils/debuggerDetector/firefoxDetector.js +64 -0
- package/dist/utils/detection.d.ts +29 -0
- package/dist/utils/detection.js +267 -0
- package/dist/utils/detectors/AbstractDevToolsDetector.d.ts +105 -0
- package/dist/utils/detectors/AbstractDevToolsDetector.js +136 -0
- package/dist/utils/detectors/dateToStringDetector.d.ts +43 -0
- package/dist/utils/detectors/dateToStringDetector.js +96 -0
- package/dist/utils/detectors/debugLibDetector.d.ts +64 -0
- package/dist/utils/detectors/debugLibDetector.js +195 -0
- package/dist/utils/detectors/debuggerDetectionWorker.d.ts +6 -0
- package/dist/utils/detectors/debuggerDetectionWorker.js +24 -0
- package/dist/utils/detectors/debuggerDetector.d.ts +51 -0
- package/dist/utils/detectors/debuggerDetector.js +211 -0
- package/dist/utils/detectors/defineGetterDetector.d.ts +48 -0
- package/dist/utils/detectors/defineGetterDetector.js +150 -0
- package/dist/utils/detectors/detectorInterface.d.ts +36 -0
- package/dist/utils/detectors/detectorInterface.js +1 -0
- package/dist/utils/detectors/devToolsDetectorManager.d.ts +88 -0
- package/dist/utils/detectors/devToolsDetectorManager.js +246 -0
- package/dist/utils/detectors/firefoxDetector.d.ts +8 -0
- package/dist/utils/detectors/firefoxDetector.js +64 -0
- package/dist/utils/detectors/funcToStringDetector.d.ts +43 -0
- package/dist/utils/detectors/funcToStringDetector.js +90 -0
- package/dist/utils/detectors/regToStringDetector.d.ts +43 -0
- package/dist/utils/detectors/regToStringDetector.js +129 -0
- package/dist/utils/detectors/sizeDetector.d.ts +54 -0
- package/dist/utils/detectors/sizeDetector.js +134 -0
- package/dist/utils/detectors/timingDetector.d.ts +55 -0
- package/dist/utils/detectors/timingDetector.js +143 -0
- package/dist/utils/dom.d.ts +20 -0
- package/dist/utils/dom.js +83 -0
- package/dist/utils/environment.d.ts +29 -0
- package/dist/utils/environment.js +267 -0
- package/dist/utils/eventManager.d.ts +167 -0
- package/dist/utils/eventManager.js +556 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/intervalManager.d.ts +96 -0
- package/dist/utils/intervalManager.js +229 -0
- package/dist/utils/keyboardShortcutManager/keyboardShortcutManager.d.ts +41 -0
- package/dist/utils/keyboardShortcutManager/keyboardShortcutManager.js +135 -0
- package/dist/utils/keyboardShortcutManager/keyboardShortcuts.d.ts +18 -0
- package/dist/utils/keyboardShortcutManager/keyboardShortcuts.js +195 -0
- package/dist/utils/logging/LogLevel.d.ts +21 -0
- package/dist/utils/logging/LogLevel.js +46 -0
- package/dist/utils/logging/LoggingConfig.d.ts +68 -0
- package/dist/utils/logging/LoggingConfig.js +64 -0
- package/dist/utils/logging/LoggingFactory.d.ts +22 -0
- package/dist/utils/logging/LoggingFactory.js +61 -0
- package/dist/utils/logging/LoggingService.d.ts +235 -0
- package/dist/utils/logging/LoggingService.js +385 -0
- package/dist/utils/logging/SimpleLoggingService.d.ts +39 -0
- package/dist/utils/logging/SimpleLoggingService.js +58 -0
- package/dist/utils/logging/advanced/LogLevel.d.ts +21 -0
- package/dist/utils/logging/advanced/LogLevel.js +46 -0
- package/dist/utils/logging/advanced/LoggingConfig.d.ts +68 -0
- package/dist/utils/logging/advanced/LoggingConfig.js +64 -0
- package/dist/utils/logging/advanced/LoggingFactory.d.ts +22 -0
- package/dist/utils/logging/advanced/LoggingFactory.js +61 -0
- package/dist/utils/logging/advanced/LoggingService.d.ts +235 -0
- package/dist/utils/logging/advanced/LoggingService.js +385 -0
- package/dist/utils/logging/simple/Loggable.d.ts +33 -0
- package/dist/utils/logging/simple/Loggable.js +1 -0
- package/dist/utils/logging/simple/LoggingDelegate.d.ts +42 -0
- package/dist/utils/logging/simple/LoggingDelegate.js +53 -0
- package/dist/utils/logging/simple/SimpleLoggingService.d.ts +39 -0
- package/dist/utils/logging/simple/SimpleLoggingService.js +58 -0
- package/dist/utils/orientation.d.ts +15 -0
- package/dist/utils/orientation.js +32 -0
- package/dist/utils/protectedContentManager-simple.d.ts +86 -0
- package/dist/utils/protectedContentManager-simple.js +180 -0
- package/dist/utils/protectedContentManager.d.ts +162 -0
- package/dist/utils/protectedContentManager.js +427 -0
- package/dist/utils/screenshotDetector.d.ts +72 -0
- package/dist/utils/screenshotDetector.js +179 -0
- package/dist/utils/securityOverlayManager-observer-pause.d.ts +283 -0
- package/dist/utils/securityOverlayManager-observer-pause.js +878 -0
- package/dist/utils/securityOverlayManager-simple.d.ts +197 -0
- package/dist/utils/securityOverlayManager-simple.js +552 -0
- package/dist/utils/securityOverlayManager.d.ts +260 -0
- package/dist/utils/securityOverlayManager.js +774 -0
- package/dist/utils/timeoutManager.d.ts +55 -0
- package/dist/utils/timeoutManager.js +121 -0
- package/package.json +54 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './KeyboardStrategy';
|
|
2
|
+
export * from './ContextMenuStrategy';
|
|
3
|
+
export * from './PrintStrategy';
|
|
4
|
+
export * from './WatermarkStrategy';
|
|
5
|
+
export * from './SelectionStrategy';
|
|
6
|
+
export * from './DevToolsStrategy';
|
|
7
|
+
export * from './ScreenshotStrategy';
|
|
8
|
+
export * from './ExtensionStrategy';
|
|
9
|
+
export * from './IFrameStrategy';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// BARREL FILE
|
|
2
|
+
export * from './KeyboardStrategy';
|
|
3
|
+
export * from './ContextMenuStrategy';
|
|
4
|
+
export * from './PrintStrategy';
|
|
5
|
+
export * from './WatermarkStrategy';
|
|
6
|
+
export * from './SelectionStrategy';
|
|
7
|
+
export * from './DevToolsStrategy';
|
|
8
|
+
export * from './ScreenshotStrategy';
|
|
9
|
+
export * from './ExtensionStrategy';
|
|
10
|
+
export * from './IFrameStrategy';
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { OverlayOptions } from "@/utils/securityOverlayManager";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for content protection
|
|
4
|
+
*/
|
|
5
|
+
export interface ContentProtectionOptions {
|
|
6
|
+
/** Enable/disable keyboard shortcuts protection */
|
|
7
|
+
preventKeyboardShortcuts?: boolean;
|
|
8
|
+
/** Enable/disable context menu protection */
|
|
9
|
+
preventContextMenu?: boolean;
|
|
10
|
+
/** Context menu protection options */
|
|
11
|
+
contextMenuOptions?: ContextMenuOptions;
|
|
12
|
+
/** Enable/disable print protection */
|
|
13
|
+
preventPrinting?: boolean;
|
|
14
|
+
/** Enable/disable selection protection */
|
|
15
|
+
preventSelection?: boolean;
|
|
16
|
+
/** Enable/disable watermarking */
|
|
17
|
+
enableWatermark?: boolean;
|
|
18
|
+
/** Enable/disable DevTools detection */
|
|
19
|
+
preventDevTools?: boolean;
|
|
20
|
+
/** Dev tools protection options */
|
|
21
|
+
devToolsOptions?: DevToolsOptions;
|
|
22
|
+
/** Enable/disable screenshot protection */
|
|
23
|
+
preventScreenshots?: boolean;
|
|
24
|
+
/** Screenshot protection options */
|
|
25
|
+
screenshotOptions?: ScreenshotOptions;
|
|
26
|
+
/** Watermark options */
|
|
27
|
+
watermarkOptions?: WatermarkOptions;
|
|
28
|
+
/** Enable/disable scraping extension protection */
|
|
29
|
+
preventExtensions?: boolean;
|
|
30
|
+
/** Extension protection options */
|
|
31
|
+
extensionOptions?: BrowserExtensionOptions;
|
|
32
|
+
/** Enable/disable iFrame protection */
|
|
33
|
+
preventEmbedding?: boolean;
|
|
34
|
+
/** iFrame protection options */
|
|
35
|
+
frameEmbeddingOptions?: FrameEmbeddingOptions;
|
|
36
|
+
/** Target element (defaults to document.body) */
|
|
37
|
+
targetElement?: HTMLElement | null;
|
|
38
|
+
/** Custom event handlers */
|
|
39
|
+
customHandlers?: CustomEventHandlers;
|
|
40
|
+
/** Enable debug mode for all strategies
|
|
41
|
+
* @default false
|
|
42
|
+
*/
|
|
43
|
+
debugMode?: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Watermark configuration options
|
|
47
|
+
*/
|
|
48
|
+
export interface WatermarkOptions {
|
|
49
|
+
/** Text to display in watermark */
|
|
50
|
+
text: string;
|
|
51
|
+
/** User identifier to include in watermark */
|
|
52
|
+
userId?: string;
|
|
53
|
+
/** Opacity of watermark (0-1) */
|
|
54
|
+
opacity?: number;
|
|
55
|
+
/** Density of watermark pattern (1-10) */
|
|
56
|
+
density?: number;
|
|
57
|
+
/** Custom styling for watermark */
|
|
58
|
+
style?: Partial<CSSStyleDeclaration>;
|
|
59
|
+
}
|
|
60
|
+
export interface ContextMenuOptions {
|
|
61
|
+
/**
|
|
62
|
+
* Whether to observe and protect iframes that are dynamically added to the DOM
|
|
63
|
+
* @default false
|
|
64
|
+
*/
|
|
65
|
+
observeForIframes?: boolean;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Clipboard protection options
|
|
69
|
+
*/
|
|
70
|
+
export interface ClipboardOptions {
|
|
71
|
+
/**
|
|
72
|
+
* Whether to prevent copy operations
|
|
73
|
+
* @default true
|
|
74
|
+
*/
|
|
75
|
+
preventCopy?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Whether to prevent cut operations
|
|
78
|
+
* @default true
|
|
79
|
+
*/
|
|
80
|
+
preventCut?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Whether to prevent paste operations
|
|
83
|
+
* @default false
|
|
84
|
+
*/
|
|
85
|
+
preventPaste?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Text to replace copied content with
|
|
88
|
+
* @default "Content copying is disabled for security reasons."
|
|
89
|
+
*/
|
|
90
|
+
replacementText?: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Screenshot protection overlay options
|
|
94
|
+
*/
|
|
95
|
+
export interface ScreenshotOptions {
|
|
96
|
+
/**
|
|
97
|
+
* Whether to show overlay when triggered
|
|
98
|
+
* @default true
|
|
99
|
+
*/
|
|
100
|
+
showOverlay?: boolean;
|
|
101
|
+
overlayOptions?: OverlayOptions;
|
|
102
|
+
/**
|
|
103
|
+
* Whether to hide sensitive content when triggered
|
|
104
|
+
* @default true
|
|
105
|
+
*/
|
|
106
|
+
hideContent?: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Whether to prevent fullscreen mode
|
|
109
|
+
* @default true
|
|
110
|
+
*/
|
|
111
|
+
preventFullscreen?: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Message to display when fullscreen is attempted
|
|
114
|
+
*/
|
|
115
|
+
fullscreenMessage?: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Options for the DevTools protection overlay
|
|
119
|
+
*/
|
|
120
|
+
export interface DevToolsOptions {
|
|
121
|
+
/**
|
|
122
|
+
* Check frequency in milliseconds
|
|
123
|
+
*/
|
|
124
|
+
checkFrequency?: number;
|
|
125
|
+
/**
|
|
126
|
+
* Whether to show overlay when triggered
|
|
127
|
+
* @default true
|
|
128
|
+
*/
|
|
129
|
+
showOverlay?: boolean;
|
|
130
|
+
overlayOptions?: OverlayOptions;
|
|
131
|
+
/**
|
|
132
|
+
* Whether to hide sensitive content when triggered
|
|
133
|
+
* @default true
|
|
134
|
+
*/
|
|
135
|
+
hideContent?: boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Specific detector types to use
|
|
138
|
+
* If empty, will use the optimal detectors for the current browser
|
|
139
|
+
*/
|
|
140
|
+
detectorTypes?: string[];
|
|
141
|
+
}
|
|
142
|
+
export interface BrowserExtensionOptions {
|
|
143
|
+
configPath?: string;
|
|
144
|
+
extensionsConfig?: Record<string, ExtensionConfig>;
|
|
145
|
+
detectionInterval?: number;
|
|
146
|
+
/**
|
|
147
|
+
* Whether to show overlay when triggered
|
|
148
|
+
* @default true
|
|
149
|
+
*/
|
|
150
|
+
showOverlay: true;
|
|
151
|
+
overlayOptions?: OverlayOptions;
|
|
152
|
+
/**
|
|
153
|
+
* Whether to hide sensitive content when triggered
|
|
154
|
+
* @default true
|
|
155
|
+
*/
|
|
156
|
+
hideContent?: boolean;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Configuration for a specific browser extension to detect
|
|
160
|
+
*/
|
|
161
|
+
export interface ExtensionConfig {
|
|
162
|
+
name: string;
|
|
163
|
+
description?: string;
|
|
164
|
+
risk: string;
|
|
165
|
+
detectionMethods: {
|
|
166
|
+
domSelectors?: string[];
|
|
167
|
+
jsSignatures?: string[];
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Options for the FrameEmbeddingProtectionStrategy
|
|
172
|
+
*/
|
|
173
|
+
export interface FrameEmbeddingOptions {
|
|
174
|
+
/**
|
|
175
|
+
* Whether to show overlay when triggered
|
|
176
|
+
* @default true
|
|
177
|
+
*/
|
|
178
|
+
showOverlay: true;
|
|
179
|
+
overlayOptions?: OverlayOptions;
|
|
180
|
+
/**
|
|
181
|
+
* Whether to hide sensitive content when triggered
|
|
182
|
+
* @default true
|
|
183
|
+
*/
|
|
184
|
+
hideContent?: boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Allowed domains that can embed the content (empty array means only same-origin is allowed)
|
|
187
|
+
*/
|
|
188
|
+
allowedDomains?: string[];
|
|
189
|
+
/**
|
|
190
|
+
* Whether to completely block the content from loading in any iframe (even same-origin)
|
|
191
|
+
*/
|
|
192
|
+
blockAllFrames?: boolean;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Custom event handlers
|
|
196
|
+
*/
|
|
197
|
+
export interface CustomEventHandlers {
|
|
198
|
+
/** Called when protection is bypassed */
|
|
199
|
+
onProtectionBypassed?: (method: string, event: Event) => void;
|
|
200
|
+
/** Called when print is attempted */
|
|
201
|
+
onPrintAttempt?: (event: Event) => void;
|
|
202
|
+
/** Called when keyboard shortcut is blocked */
|
|
203
|
+
onKeyboardShortcutBlocked?: (event: KeyboardEvent) => void;
|
|
204
|
+
/** Called when DevTools is opened or closed */
|
|
205
|
+
onDevToolsOpen?: (isOpen: boolean) => void;
|
|
206
|
+
/** Called when a clipboard operation is detected */
|
|
207
|
+
onClipboardAttempt?: (event: Event, action: "copy" | "cut" | "paste") => void;
|
|
208
|
+
onContextMenuAttempt?: (event: Event) => void;
|
|
209
|
+
onSelectionAttempt?: (event: Event) => void;
|
|
210
|
+
onScreenshotAttempt?: (event: Event) => void;
|
|
211
|
+
onExtensionDetected?: (extensionId: string, extensionName: string, riskLevel: "low" | "medium" | "high") => void;
|
|
212
|
+
onFrameEmbeddingDetected?: (isEmbedded: boolean, isExternalFrame: boolean) => void;
|
|
213
|
+
/**
|
|
214
|
+
* Called when content is hidden due to a security event (e.g., DevTools opened)
|
|
215
|
+
* @param reason The reason why content was hidden
|
|
216
|
+
* @param targetElement The element whose content was hidden
|
|
217
|
+
*/
|
|
218
|
+
onContentHidden?: (reason: string, targetElement: HTMLElement | null) => void;
|
|
219
|
+
/**
|
|
220
|
+
* Called when content is restored after a security event clears (e.g., DevTools closed)
|
|
221
|
+
* Useful for frameworks like Vue to re-mount components after innerHTML restoration
|
|
222
|
+
* @param targetElement The element whose content was restored
|
|
223
|
+
*/
|
|
224
|
+
onContentRestored?: (targetElement: HTMLElement | null) => void;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Protection strategy interface
|
|
228
|
+
*/
|
|
229
|
+
export interface ProtectionStrategy {
|
|
230
|
+
/**
|
|
231
|
+
* Unique identifier for the strategy
|
|
232
|
+
* Used for logging and event management
|
|
233
|
+
*/
|
|
234
|
+
readonly STRATEGY_NAME: string;
|
|
235
|
+
/** Apply the protection strategy */
|
|
236
|
+
apply(options?: unknown): void;
|
|
237
|
+
/** Remove the protection strategy */
|
|
238
|
+
remove(): void;
|
|
239
|
+
/** Check if strategy is currently applied */
|
|
240
|
+
isApplied(): boolean;
|
|
241
|
+
/** Update strategy options */
|
|
242
|
+
updateOptions(options: Record<string, unknown>): void;
|
|
243
|
+
/** Get the debug mode status
|
|
244
|
+
* @returns True if debug mode is enabled
|
|
245
|
+
*/
|
|
246
|
+
isDebugEnabled(): boolean;
|
|
247
|
+
/** Set debug mode
|
|
248
|
+
* @param enabled Whether debug mode should be enabled
|
|
249
|
+
*/
|
|
250
|
+
setDebugMode(enabled: boolean): void;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Protection strategy names
|
|
254
|
+
*/
|
|
255
|
+
export declare enum StrategyName {
|
|
256
|
+
KEYBOARD = "KeyboardStrategy",
|
|
257
|
+
CONTEXT_MENU = "ContextMenuStrategy",
|
|
258
|
+
PRINT = "PrintStrategy",
|
|
259
|
+
SELECTION = "SelectionStrategy",
|
|
260
|
+
WATERMARK = "WatermarkStrategy",
|
|
261
|
+
DEV_TOOLS = "DevToolsStrategy",
|
|
262
|
+
SCREENSHOT = "ScreenshotStrategy",
|
|
263
|
+
BROWSER_EXTENSION = "BrowserExtensionStrategy",
|
|
264
|
+
FRAME_EMBEDDING = "FrameEmbeddingStrategy",
|
|
265
|
+
CLIPBOARD = "ClipboardStrategy"
|
|
266
|
+
}
|
|
267
|
+
declare global {
|
|
268
|
+
interface Console {
|
|
269
|
+
exception?: (...data: unknown[]) => void;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protection strategy names
|
|
3
|
+
*/
|
|
4
|
+
export var StrategyName;
|
|
5
|
+
(function (StrategyName) {
|
|
6
|
+
StrategyName["KEYBOARD"] = "KeyboardStrategy";
|
|
7
|
+
StrategyName["CONTEXT_MENU"] = "ContextMenuStrategy";
|
|
8
|
+
StrategyName["PRINT"] = "PrintStrategy";
|
|
9
|
+
StrategyName["SELECTION"] = "SelectionStrategy";
|
|
10
|
+
StrategyName["WATERMARK"] = "WatermarkStrategy";
|
|
11
|
+
StrategyName["DEV_TOOLS"] = "DevToolsStrategy";
|
|
12
|
+
StrategyName["SCREENSHOT"] = "ScreenshotStrategy";
|
|
13
|
+
StrategyName["BROWSER_EXTENSION"] = "BrowserExtensionStrategy";
|
|
14
|
+
StrategyName["FRAME_EMBEDDING"] = "FrameEmbeddingStrategy";
|
|
15
|
+
StrategyName["CLIPBOARD"] = "ClipboardStrategy";
|
|
16
|
+
})(StrategyName || (StrategyName = {}));
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for the DOM observer
|
|
3
|
+
*/
|
|
4
|
+
export interface DomObserverOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Target element to observe
|
|
7
|
+
*/
|
|
8
|
+
targetElement: HTMLElement;
|
|
9
|
+
/**
|
|
10
|
+
* Callback function when elements are removed
|
|
11
|
+
*/
|
|
12
|
+
onElementsRemoved?: (removedElements: HTMLElement[]) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Callback function when elements are added
|
|
15
|
+
*/
|
|
16
|
+
onElementsAdded?: (addedElements: HTMLElement[]) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Elements to watch for removal
|
|
19
|
+
*/
|
|
20
|
+
elementsToWatch: HTMLElement[];
|
|
21
|
+
/**
|
|
22
|
+
* Whether to observe child elements as well
|
|
23
|
+
*/
|
|
24
|
+
observeSubtree?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Enable debug mode for troubleshooting
|
|
27
|
+
*/
|
|
28
|
+
debugMode?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Custom name for logging
|
|
31
|
+
*/
|
|
32
|
+
name?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Helper class to observe DOM changes and detect when specific elements are added or removed
|
|
36
|
+
*/
|
|
37
|
+
export declare class DomObserver {
|
|
38
|
+
private observer;
|
|
39
|
+
private options;
|
|
40
|
+
private isObserving;
|
|
41
|
+
/**
|
|
42
|
+
* Create a new DOM observer
|
|
43
|
+
* @param options Observer options
|
|
44
|
+
*/
|
|
45
|
+
constructor(options: DomObserverOptions);
|
|
46
|
+
/**
|
|
47
|
+
* Start observing the DOM for changes
|
|
48
|
+
*/
|
|
49
|
+
startObserving(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Stop observing the DOM
|
|
52
|
+
*/
|
|
53
|
+
stopObserving(): void;
|
|
54
|
+
/**
|
|
55
|
+
* Update the elements to watch
|
|
56
|
+
* @param elements New elements to watch
|
|
57
|
+
*/
|
|
58
|
+
updateElementsToWatch(elements: HTMLElement[]): void;
|
|
59
|
+
/**
|
|
60
|
+
* Update the target element
|
|
61
|
+
* @param element New target element
|
|
62
|
+
*/
|
|
63
|
+
updateTargetElement(element: HTMLElement): void;
|
|
64
|
+
/**
|
|
65
|
+
* Check if the observer is currently observing
|
|
66
|
+
*/
|
|
67
|
+
isActive(): boolean;
|
|
68
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper class to observe DOM changes and detect when specific elements are added or removed
|
|
3
|
+
*/
|
|
4
|
+
export class DomObserver {
|
|
5
|
+
/**
|
|
6
|
+
* Create a new DOM observer
|
|
7
|
+
* @param options Observer options
|
|
8
|
+
*/
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.observer = null;
|
|
11
|
+
this.isObserving = false;
|
|
12
|
+
this.options = {
|
|
13
|
+
observeSubtree: true,
|
|
14
|
+
debugMode: false,
|
|
15
|
+
name: 'DomObserver',
|
|
16
|
+
...options,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Start observing the DOM for changes
|
|
21
|
+
*/
|
|
22
|
+
startObserving() {
|
|
23
|
+
if (this.isObserving || typeof MutationObserver === 'undefined' || !this.options.targetElement) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// Remove any existing observer
|
|
27
|
+
this.stopObserving();
|
|
28
|
+
// Create a new observer
|
|
29
|
+
this.observer = new MutationObserver((mutations) => {
|
|
30
|
+
const removedElements = [];
|
|
31
|
+
const addedElements = [];
|
|
32
|
+
for (const mutation of mutations) {
|
|
33
|
+
if (mutation.type === 'childList') {
|
|
34
|
+
// Check if any of our watched elements were removed
|
|
35
|
+
for (const node of Array.from(mutation.removedNodes)) {
|
|
36
|
+
if (node instanceof HTMLElement) {
|
|
37
|
+
if (this.options.elementsToWatch.includes(node)) {
|
|
38
|
+
removedElements.push(node);
|
|
39
|
+
if (this.options.debugMode) {
|
|
40
|
+
console.log(`${this.options.name}: Watched element was removed from DOM`, node);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Check for added nodes if we have an onElementsAdded callback
|
|
46
|
+
if (this.options.onElementsAdded) {
|
|
47
|
+
for (const node of Array.from(mutation.addedNodes)) {
|
|
48
|
+
if (node instanceof HTMLElement) {
|
|
49
|
+
addedElements.push(node);
|
|
50
|
+
// If we're observing the subtree, also check for child elements
|
|
51
|
+
if (this.options.observeSubtree) {
|
|
52
|
+
const childElements = node.querySelectorAll("*");
|
|
53
|
+
childElements.forEach((child) => {
|
|
54
|
+
if (child instanceof HTMLElement) {
|
|
55
|
+
addedElements.push(child);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (this.options.debugMode) {
|
|
60
|
+
console.log(`${this.options.name}: Element was added to DOM`, node);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Call callbacks if we have elements to report
|
|
68
|
+
if (removedElements.length > 0 && this.options.onElementsRemoved) {
|
|
69
|
+
this.options.onElementsRemoved(removedElements);
|
|
70
|
+
}
|
|
71
|
+
if (addedElements.length > 0 && this.options.onElementsAdded) {
|
|
72
|
+
this.options.onElementsAdded(addedElements);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
// Start observing the target element
|
|
76
|
+
this.observer.observe(this.options.targetElement, {
|
|
77
|
+
childList: true,
|
|
78
|
+
subtree: this.options.observeSubtree,
|
|
79
|
+
});
|
|
80
|
+
this.isObserving = true;
|
|
81
|
+
if (this.options.debugMode) {
|
|
82
|
+
console.log(`${this.options.name}: Started observing`, {
|
|
83
|
+
target: this.options.targetElement,
|
|
84
|
+
elementsCount: this.options.elementsToWatch.length,
|
|
85
|
+
subtree: this.options.observeSubtree,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Stop observing the DOM
|
|
91
|
+
*/
|
|
92
|
+
stopObserving() {
|
|
93
|
+
if (this.observer) {
|
|
94
|
+
this.observer.disconnect();
|
|
95
|
+
this.observer = null;
|
|
96
|
+
this.isObserving = false;
|
|
97
|
+
if (this.options.debugMode) {
|
|
98
|
+
console.log(`${this.options.name}: Stopped observing`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Update the elements to watch
|
|
104
|
+
* @param elements New elements to watch
|
|
105
|
+
*/
|
|
106
|
+
updateElementsToWatch(elements) {
|
|
107
|
+
this.options.elementsToWatch = elements;
|
|
108
|
+
if (this.isObserving && this.options.debugMode) {
|
|
109
|
+
console.log(`${this.options.name}: Updated elements to watch`, {
|
|
110
|
+
elementsCount: elements.length,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Update the target element
|
|
116
|
+
* @param element New target element
|
|
117
|
+
*/
|
|
118
|
+
updateTargetElement(element) {
|
|
119
|
+
if (this.options.targetElement !== element) {
|
|
120
|
+
this.options.targetElement = element;
|
|
121
|
+
// Restart observing with the new target
|
|
122
|
+
if (this.isObserving) {
|
|
123
|
+
this.stopObserving();
|
|
124
|
+
this.startObserving();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Check if the observer is currently observing
|
|
130
|
+
*/
|
|
131
|
+
isActive() {
|
|
132
|
+
return this.isObserving;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { SimpleLoggingService } from "../logging/simple/SimpleLoggingService";
|
|
2
|
+
/**
|
|
3
|
+
* Base class providing common logging and error handling functionality.
|
|
4
|
+
* Extract shared functionality from AbstractStrategy, AbstractDevToolsDetector, and AbstractEventHandler.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class LoggableComponent {
|
|
7
|
+
readonly COMPONENT_NAME: string;
|
|
8
|
+
protected debugMode: boolean;
|
|
9
|
+
protected logger: SimpleLoggingService;
|
|
10
|
+
/**
|
|
11
|
+
* Create a new LoggableComponent
|
|
12
|
+
* @param componentName Unique name for the component (used in logging)
|
|
13
|
+
* @param debugMode Enable debug mode for troubleshooting
|
|
14
|
+
*/
|
|
15
|
+
constructor(componentName: string, debugMode?: boolean);
|
|
16
|
+
/**
|
|
17
|
+
* Get the debug mode status
|
|
18
|
+
* @returns True if debug mode is enabled
|
|
19
|
+
*/
|
|
20
|
+
isDebugEnabled(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Set debug mode
|
|
23
|
+
* @param enabled Whether debug mode should be enabled
|
|
24
|
+
*/
|
|
25
|
+
setDebugMode(enabled: boolean): void;
|
|
26
|
+
/**
|
|
27
|
+
* Log a debug message if debug mode is enabled
|
|
28
|
+
* @param message Message to log
|
|
29
|
+
* @param args Additional arguments to log
|
|
30
|
+
*/
|
|
31
|
+
protected log(message: string, ...args: unknown[]): void;
|
|
32
|
+
/**
|
|
33
|
+
* Log a warning message
|
|
34
|
+
* @param message Warning message
|
|
35
|
+
* @param args Additional arguments to log
|
|
36
|
+
*/
|
|
37
|
+
protected warn(message: string, ...args: unknown[]): void;
|
|
38
|
+
/**
|
|
39
|
+
* Log an error message
|
|
40
|
+
* @param message Error message
|
|
41
|
+
* @param args Additional arguments to log
|
|
42
|
+
*/
|
|
43
|
+
protected error(message: string, ...args: unknown[]): void;
|
|
44
|
+
/**
|
|
45
|
+
* Execute a function with error handling
|
|
46
|
+
* This method can be overridden in subclasses to add type-specific error handling.
|
|
47
|
+
* @param operation Name of the operation for error reporting
|
|
48
|
+
* @param errorTypeOrFn Either an error type (for subclasses) or the function to execute
|
|
49
|
+
* @param fn Function to execute (only if errorTypeOrFn is an error type)
|
|
50
|
+
* @returns The result of the function or undefined if an error occurred
|
|
51
|
+
*/
|
|
52
|
+
protected safeExecute<T>(operation: string, errorTypeOrFn: unknown, fn?: () => T): T | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Execute an async function with error handling
|
|
55
|
+
* This method can be overridden in subclasses to add type-specific error handling.
|
|
56
|
+
* @param operation Name of the operation for error reporting
|
|
57
|
+
* @param errorTypeOrFn Either an error type (for subclasses) or the async function to execute
|
|
58
|
+
* @param fn Async function to execute (only if errorTypeOrFn is an error type)
|
|
59
|
+
* @returns Promise resolving to the result of the function or undefined if an error occurred
|
|
60
|
+
*/
|
|
61
|
+
protected safeExecuteAsync<T>(operation: string, errorTypeOrFn: unknown, fn?: () => Promise<T>): Promise<T | undefined>;
|
|
62
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { SimpleLoggingService } from "../logging/simple/SimpleLoggingService";
|
|
2
|
+
/**
|
|
3
|
+
* Base class providing common logging and error handling functionality.
|
|
4
|
+
* Extract shared functionality from AbstractStrategy, AbstractDevToolsDetector, and AbstractEventHandler.
|
|
5
|
+
*/
|
|
6
|
+
export class LoggableComponent {
|
|
7
|
+
/**
|
|
8
|
+
* Create a new LoggableComponent
|
|
9
|
+
* @param componentName Unique name for the component (used in logging)
|
|
10
|
+
* @param debugMode Enable debug mode for troubleshooting
|
|
11
|
+
*/
|
|
12
|
+
constructor(componentName, debugMode = false) {
|
|
13
|
+
this.COMPONENT_NAME = componentName;
|
|
14
|
+
this.debugMode = debugMode;
|
|
15
|
+
this.logger = new SimpleLoggingService(componentName, debugMode);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get the debug mode status
|
|
19
|
+
* @returns True if debug mode is enabled
|
|
20
|
+
*/
|
|
21
|
+
isDebugEnabled() {
|
|
22
|
+
return this.debugMode;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Set debug mode
|
|
26
|
+
* @param enabled Whether debug mode should be enabled
|
|
27
|
+
*/
|
|
28
|
+
setDebugMode(enabled) {
|
|
29
|
+
this.debugMode = enabled;
|
|
30
|
+
this.logger.setDebugMode(enabled);
|
|
31
|
+
this.logger.log(`Debug mode ${enabled ? "enabled" : "disabled"}`);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Log a debug message if debug mode is enabled
|
|
35
|
+
* @param message Message to log
|
|
36
|
+
* @param args Additional arguments to log
|
|
37
|
+
*/
|
|
38
|
+
log(message, ...args) {
|
|
39
|
+
this.logger.log(message, ...args);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Log a warning message
|
|
43
|
+
* @param message Warning message
|
|
44
|
+
* @param args Additional arguments to log
|
|
45
|
+
*/
|
|
46
|
+
warn(message, ...args) {
|
|
47
|
+
this.logger.warn(message, ...args);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Log an error message
|
|
51
|
+
* @param message Error message
|
|
52
|
+
* @param args Additional arguments to log
|
|
53
|
+
*/
|
|
54
|
+
error(message, ...args) {
|
|
55
|
+
this.logger.error(message, ...args);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Execute a function with error handling
|
|
59
|
+
* This method can be overridden in subclasses to add type-specific error handling.
|
|
60
|
+
* @param operation Name of the operation for error reporting
|
|
61
|
+
* @param errorTypeOrFn Either an error type (for subclasses) or the function to execute
|
|
62
|
+
* @param fn Function to execute (only if errorTypeOrFn is an error type)
|
|
63
|
+
* @returns The result of the function or undefined if an error occurred
|
|
64
|
+
*/
|
|
65
|
+
safeExecute(operation, errorTypeOrFn, fn) {
|
|
66
|
+
// If only two args were provided (operation, fn), fn is actually in errorTypeOrFn
|
|
67
|
+
const actualFn = fn || errorTypeOrFn;
|
|
68
|
+
try {
|
|
69
|
+
return actualFn();
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
this.logger.error(`Error during ${operation}:`, error);
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Execute an async function with error handling
|
|
78
|
+
* This method can be overridden in subclasses to add type-specific error handling.
|
|
79
|
+
* @param operation Name of the operation for error reporting
|
|
80
|
+
* @param errorTypeOrFn Either an error type (for subclasses) or the async function to execute
|
|
81
|
+
* @param fn Async function to execute (only if errorTypeOrFn is an error type)
|
|
82
|
+
* @returns Promise resolving to the result of the function or undefined if an error occurred
|
|
83
|
+
*/
|
|
84
|
+
async safeExecuteAsync(operation, errorTypeOrFn, fn) {
|
|
85
|
+
// If only two args were provided (operation, fn), fn is actually in errorTypeOrFn
|
|
86
|
+
const actualFn = fn || errorTypeOrFn;
|
|
87
|
+
try {
|
|
88
|
+
return await actualFn();
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
this.logger.error(`Error during ${operation}:`, error);
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|