content-security-toolkit 1.0.0 → 1.0.1
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/README.md +203 -41
- package/package.json +12 -5
- package/dist/core/mediator/handlers/baseEventHandler.d.ts +0 -65
- package/dist/core/mediator/handlers/baseEventHandler.js +0 -99
- package/dist/core/mediator/handlers/index.d.ts +0 -9
- package/dist/core/mediator/handlers/index.js +0 -34
- package/dist/strategies/AbstractStrategy.mediator.d.ts +0 -162
- package/dist/strategies/AbstractStrategy.mediator.js +0 -349
- package/dist/strategies/DevToolsStrategy copy.d.ts +0 -85
- package/dist/strategies/DevToolsStrategy copy.js +0 -362
- package/dist/strategies/DevToolsStrategy-detectorManager.d.ts +0 -70
- package/dist/strategies/DevToolsStrategy-detectorManager.js +0 -309
- package/dist/strategies/DevToolsStrategy-simple.d.ts +0 -75
- package/dist/strategies/DevToolsStrategy-simple.js +0 -366
- package/dist/strategies/StrategyRegistry.d.ts +0 -133
- package/dist/strategies/StrategyRegistry.js +0 -379
- package/dist/utils/base/LoggableComponent.d.ts +0 -62
- package/dist/utils/base/LoggableComponent.js +0 -95
- package/dist/utils/debuggerDetector/debuggerDetectionWorker.d.ts +0 -6
- package/dist/utils/debuggerDetector/debuggerDetectionWorker.js +0 -24
- package/dist/utils/debuggerDetector/debuggerDetector.d.ts +0 -55
- package/dist/utils/debuggerDetector/debuggerDetector.js +0 -158
- package/dist/utils/debuggerDetector/firefoxDetector.d.ts +0 -8
- package/dist/utils/debuggerDetector/firefoxDetector.js +0 -64
- package/dist/utils/detection.d.ts +0 -29
- package/dist/utils/detection.js +0 -267
- package/dist/utils/detectors/debuggerDetectionWorker.d.ts +0 -6
- package/dist/utils/detectors/debuggerDetectionWorker.js +0 -24
- package/dist/utils/detectors/firefoxDetector.d.ts +0 -8
- package/dist/utils/detectors/firefoxDetector.js +0 -64
- package/dist/utils/logging/LogLevel.d.ts +0 -21
- package/dist/utils/logging/LogLevel.js +0 -46
- package/dist/utils/logging/LoggingConfig.d.ts +0 -68
- package/dist/utils/logging/LoggingConfig.js +0 -64
- package/dist/utils/logging/LoggingFactory.d.ts +0 -22
- package/dist/utils/logging/LoggingFactory.js +0 -61
- package/dist/utils/logging/LoggingService.d.ts +0 -235
- package/dist/utils/logging/LoggingService.js +0 -385
- package/dist/utils/logging/SimpleLoggingService.d.ts +0 -39
- package/dist/utils/logging/SimpleLoggingService.js +0 -58
- package/dist/utils/logging/advanced/LogLevel.d.ts +0 -21
- package/dist/utils/logging/advanced/LogLevel.js +0 -46
- package/dist/utils/logging/advanced/LoggingConfig.d.ts +0 -68
- package/dist/utils/logging/advanced/LoggingConfig.js +0 -64
- package/dist/utils/logging/advanced/LoggingFactory.d.ts +0 -22
- package/dist/utils/logging/advanced/LoggingFactory.js +0 -61
- package/dist/utils/logging/advanced/LoggingService.d.ts +0 -235
- package/dist/utils/logging/advanced/LoggingService.js +0 -385
- package/dist/utils/protectedContentManager-simple.d.ts +0 -86
- package/dist/utils/protectedContentManager-simple.js +0 -180
- package/dist/utils/securityOverlayManager-observer-pause.d.ts +0 -283
- package/dist/utils/securityOverlayManager-observer-pause.js +0 -878
- package/dist/utils/securityOverlayManager-simple.d.ts +0 -197
- package/dist/utils/securityOverlayManager-simple.js +0 -552
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import type { ProtectionStrategy } from "../types";
|
|
2
|
-
import type { ProtectionMediator, ProtectionEventHandler, SubscriptionOptions } from "../core/mediator/types";
|
|
3
|
-
import { ProtectionEventType } from "../core/mediator/protection-event";
|
|
4
|
-
import type { EventDataMap } from "../core/mediator/eventDataTypes";
|
|
5
|
-
/**
|
|
6
|
-
* Error types for protection strategies
|
|
7
|
-
*/
|
|
8
|
-
export declare enum StrategyErrorType {
|
|
9
|
-
INITIALIZATION = "initialization",
|
|
10
|
-
APPLICATION = "application",
|
|
11
|
-
REMOVAL = "removal",
|
|
12
|
-
EVENT_HANDLING = "event_handling",
|
|
13
|
-
OPTION_UPDATE = "option_update",
|
|
14
|
-
UNKNOWN = "unknown"
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Custom error class for protection strategies
|
|
18
|
-
*/
|
|
19
|
-
export declare class StrategyError extends Error {
|
|
20
|
-
readonly strategyName: string;
|
|
21
|
-
readonly errorType: StrategyErrorType;
|
|
22
|
-
readonly originalError?: (Error | unknown) | undefined;
|
|
23
|
-
/**
|
|
24
|
-
* Create a new StrategyError
|
|
25
|
-
* @param strategyName Name of the strategy where the error occurred
|
|
26
|
-
* @param errorType Type of error that occurred
|
|
27
|
-
* @param message Error message
|
|
28
|
-
* @param originalError Original error that was caught (if any)
|
|
29
|
-
*/
|
|
30
|
-
constructor(strategyName: string, errorType: StrategyErrorType, message: string, originalError?: (Error | unknown) | undefined);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Abstract base class for protection strategies
|
|
34
|
-
* Implements common functionality to reduce duplication
|
|
35
|
-
*/
|
|
36
|
-
export declare abstract class AbstractStrategy implements ProtectionStrategy {
|
|
37
|
-
protected mediator: ProtectionMediator | null;
|
|
38
|
-
protected subscriptionIds: string[];
|
|
39
|
-
readonly STRATEGY_NAME: string;
|
|
40
|
-
protected isAppliedFlag: boolean;
|
|
41
|
-
protected debugMode: boolean;
|
|
42
|
-
protected eventIds: string[];
|
|
43
|
-
/**
|
|
44
|
-
* Create a new strategy
|
|
45
|
-
* @param strategyName Unique name for the strategy
|
|
46
|
-
* @param debugMode Enable debug mode for troubleshooting
|
|
47
|
-
*/
|
|
48
|
-
constructor(strategyName: string, debugMode?: boolean);
|
|
49
|
-
/**
|
|
50
|
-
* Apply the protection strategy
|
|
51
|
-
* Must be implemented by subclasses
|
|
52
|
-
*/
|
|
53
|
-
abstract apply(): void;
|
|
54
|
-
/**
|
|
55
|
-
* Set the mediator for this strategy
|
|
56
|
-
* This connects the strategy to the event system
|
|
57
|
-
* @param mediator The protection mediator instance
|
|
58
|
-
*/
|
|
59
|
-
setMediator(mediator: ProtectionMediator): void;
|
|
60
|
-
/**
|
|
61
|
-
* Helper method for subscribing to events
|
|
62
|
-
* Tracks subscription IDs for cleanup
|
|
63
|
-
*/
|
|
64
|
-
protected subscribe(eventType: ProtectionEventType, handler: ProtectionEventHandler, options?: SubscriptionOptions): string;
|
|
65
|
-
/**
|
|
66
|
-
* Helper method for publishing events
|
|
67
|
-
*/
|
|
68
|
-
protected publishEvent<T extends ProtectionEventType>(eventType: T, data?: EventDataMap[T]): void;
|
|
69
|
-
/**
|
|
70
|
-
* Remove the protection strategy
|
|
71
|
-
* Can be overridden by subclasses for custom cleanup
|
|
72
|
-
*/
|
|
73
|
-
remove(): void;
|
|
74
|
-
/**
|
|
75
|
-
* Check if the strategy is currently applied
|
|
76
|
-
*/
|
|
77
|
-
isApplied(): boolean;
|
|
78
|
-
/**
|
|
79
|
-
* Update strategy options
|
|
80
|
-
* Should be implemented by subclasses that support options
|
|
81
|
-
*/
|
|
82
|
-
updateOptions(options: Record<string, unknown>): void;
|
|
83
|
-
/**
|
|
84
|
-
* Get the debug mode status
|
|
85
|
-
*/
|
|
86
|
-
isDebugEnabled(): boolean;
|
|
87
|
-
/**
|
|
88
|
-
* Set debug mode
|
|
89
|
-
*/
|
|
90
|
-
setDebugMode(enabled: boolean): void;
|
|
91
|
-
/**
|
|
92
|
-
* Handle an error that occurred in the strategy
|
|
93
|
-
* @param errorType Type of error
|
|
94
|
-
* @param message Error message
|
|
95
|
-
* @param originalError Original error that was caught
|
|
96
|
-
*/
|
|
97
|
-
protected handleError(errorType: StrategyErrorType, message: string, originalError?: unknown): void;
|
|
98
|
-
/**
|
|
99
|
-
* Log a debug message if debug mode is enabled
|
|
100
|
-
* @param message Message to log
|
|
101
|
-
* @param args Additional arguments to log
|
|
102
|
-
*/
|
|
103
|
-
protected log(message: string, ...args: unknown[]): void;
|
|
104
|
-
/**
|
|
105
|
-
* Log a warning message
|
|
106
|
-
* @param message Warning message
|
|
107
|
-
* @param args Additional arguments to log
|
|
108
|
-
*/
|
|
109
|
-
protected warn(message: string, ...args: unknown[]): void;
|
|
110
|
-
/**
|
|
111
|
-
* Log an error message
|
|
112
|
-
* @param message Error message
|
|
113
|
-
* @param args Additional arguments to log
|
|
114
|
-
*/
|
|
115
|
-
protected error(message: string, ...args: unknown[]): void;
|
|
116
|
-
/**
|
|
117
|
-
* Execute a function with error handling
|
|
118
|
-
* @param operation Name of the operation for error reporting
|
|
119
|
-
* @param errorType Type of error for categorization
|
|
120
|
-
* @param fn Function to execute
|
|
121
|
-
* @returns The result of the function or undefined if an error occurred
|
|
122
|
-
*/
|
|
123
|
-
protected safeExecute<T>(operation: string, errorType: StrategyErrorType, fn: () => T): T | undefined;
|
|
124
|
-
/**
|
|
125
|
-
* Execute an async function with error handling
|
|
126
|
-
* @param operation Name of the operation for error reporting
|
|
127
|
-
* @param errorType Type of error for categorization
|
|
128
|
-
* @param fn Async function to execute
|
|
129
|
-
* @returns Promise resolving to the result of the function or undefined if an error occurred
|
|
130
|
-
*/
|
|
131
|
-
protected safeExecuteAsync<T>(operation: string, errorType: StrategyErrorType, fn: () => Promise<T>): Promise<T | undefined>;
|
|
132
|
-
/**
|
|
133
|
-
* Register an event with the EventManager
|
|
134
|
-
* @param target The target element, document, or window
|
|
135
|
-
* @param eventType The type of event (e.g., "click", "keydown")
|
|
136
|
-
* @param handler The event handler function
|
|
137
|
-
* @param options Additional options for the event listener
|
|
138
|
-
* @returns The ID of the registered event
|
|
139
|
-
*/
|
|
140
|
-
protected registerEvent(target: EventTarget | null, eventType: string, handler: EventListener, options?: AddEventListenerOptions & {
|
|
141
|
-
priority?: number;
|
|
142
|
-
id?: string;
|
|
143
|
-
}): string;
|
|
144
|
-
/**
|
|
145
|
-
* Remove all event listeners for this strategy
|
|
146
|
-
* @returns The number of events removed
|
|
147
|
-
*/
|
|
148
|
-
protected removeEventsByOwner(): number;
|
|
149
|
-
/**
|
|
150
|
-
* Remove all event listeners for a specific target
|
|
151
|
-
* @param target The target to remove events from
|
|
152
|
-
* @returns The number of events removed
|
|
153
|
-
*/
|
|
154
|
-
protected removeAllEventsForTarget(target: EventTarget | null): number;
|
|
155
|
-
/**
|
|
156
|
-
* Remove event listeners by CSS selector
|
|
157
|
-
* @param selector CSS selector to match elements
|
|
158
|
-
* @param eventType Type of event to remove
|
|
159
|
-
* @returns The number of events removed
|
|
160
|
-
*/
|
|
161
|
-
protected removeEventsBySelector(selector: string, eventType: string): number;
|
|
162
|
-
}
|
|
@@ -1,349 +0,0 @@
|
|
|
1
|
-
import { eventManager } from "../utils/eventManager";
|
|
2
|
-
import { isBrowser } from "../utils/detection";
|
|
3
|
-
import { ProtectionEventType } from "../core/mediator/protection-event";
|
|
4
|
-
/**
|
|
5
|
-
* Error types for protection strategies
|
|
6
|
-
*/
|
|
7
|
-
export var StrategyErrorType;
|
|
8
|
-
(function (StrategyErrorType) {
|
|
9
|
-
StrategyErrorType["INITIALIZATION"] = "initialization";
|
|
10
|
-
StrategyErrorType["APPLICATION"] = "application";
|
|
11
|
-
StrategyErrorType["REMOVAL"] = "removal";
|
|
12
|
-
StrategyErrorType["EVENT_HANDLING"] = "event_handling";
|
|
13
|
-
StrategyErrorType["OPTION_UPDATE"] = "option_update";
|
|
14
|
-
StrategyErrorType["UNKNOWN"] = "unknown";
|
|
15
|
-
})(StrategyErrorType || (StrategyErrorType = {}));
|
|
16
|
-
/**
|
|
17
|
-
* Custom error class for protection strategies
|
|
18
|
-
*/
|
|
19
|
-
export class StrategyError extends Error {
|
|
20
|
-
/**
|
|
21
|
-
* Create a new StrategyError
|
|
22
|
-
* @param strategyName Name of the strategy where the error occurred
|
|
23
|
-
* @param errorType Type of error that occurred
|
|
24
|
-
* @param message Error message
|
|
25
|
-
* @param originalError Original error that was caught (if any)
|
|
26
|
-
*/
|
|
27
|
-
constructor(strategyName, errorType, message, originalError) {
|
|
28
|
-
super(`[${strategyName}] ${message}${originalError instanceof Error ? `: ${originalError.message}` : ""}`);
|
|
29
|
-
this.strategyName = strategyName;
|
|
30
|
-
this.errorType = errorType;
|
|
31
|
-
this.originalError = originalError;
|
|
32
|
-
this.name = "StrategyError";
|
|
33
|
-
// Maintain the stack trace
|
|
34
|
-
if (Error.captureStackTrace) {
|
|
35
|
-
Error.captureStackTrace(this, StrategyError);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Abstract base class for protection strategies
|
|
41
|
-
* Implements common functionality to reduce duplication
|
|
42
|
-
*/
|
|
43
|
-
export class AbstractStrategy {
|
|
44
|
-
/**
|
|
45
|
-
* Create a new strategy
|
|
46
|
-
* @param strategyName Unique name for the strategy
|
|
47
|
-
* @param debugMode Enable debug mode for troubleshooting
|
|
48
|
-
*/
|
|
49
|
-
constructor(strategyName, debugMode = false) {
|
|
50
|
-
this.mediator = null;
|
|
51
|
-
this.subscriptionIds = []; // For tracking event subscriptions
|
|
52
|
-
this.isAppliedFlag = false;
|
|
53
|
-
this.debugMode = false;
|
|
54
|
-
this.eventIds = [];
|
|
55
|
-
this.STRATEGY_NAME = strategyName;
|
|
56
|
-
this.debugMode = debugMode;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Set the mediator for this strategy
|
|
60
|
-
* This connects the strategy to the event system
|
|
61
|
-
* @param mediator The protection mediator instance
|
|
62
|
-
*/
|
|
63
|
-
setMediator(mediator) {
|
|
64
|
-
if (this.mediator === mediator)
|
|
65
|
-
return; // Avoid redundant setup
|
|
66
|
-
// Clean up any existing subscriptions if we're changing mediators
|
|
67
|
-
if (this.mediator && this.subscriptionIds.length > 0) {
|
|
68
|
-
this.subscriptionIds.forEach((id) => this.mediator?.unsubscribe(id));
|
|
69
|
-
this.subscriptionIds = [];
|
|
70
|
-
}
|
|
71
|
-
this.mediator = mediator;
|
|
72
|
-
this.log(`Connected to mediator`);
|
|
73
|
-
// Base class doesn't subscribe to any events by default
|
|
74
|
-
// Specific strategies will override this method to add their subscriptions
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Helper method for subscribing to events
|
|
78
|
-
* Tracks subscription IDs for cleanup
|
|
79
|
-
*/
|
|
80
|
-
subscribe(eventType, handler, options) {
|
|
81
|
-
if (!this.mediator) {
|
|
82
|
-
this.warn(`Cannot subscribe to ${eventType} - no mediator set`);
|
|
83
|
-
return "";
|
|
84
|
-
}
|
|
85
|
-
const id = this.mediator.subscribe(eventType, handler, {
|
|
86
|
-
...options,
|
|
87
|
-
context: this.STRATEGY_NAME, // Always include strategy name as context
|
|
88
|
-
});
|
|
89
|
-
if (id) {
|
|
90
|
-
this.subscriptionIds.push(id);
|
|
91
|
-
}
|
|
92
|
-
return id;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Helper method for publishing events
|
|
96
|
-
*/
|
|
97
|
-
publishEvent(eventType, data) {
|
|
98
|
-
if (!this.mediator) {
|
|
99
|
-
this.warn(`Cannot publish ${eventType} - no mediator set`);
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
this.mediator.publish({
|
|
103
|
-
type: eventType,
|
|
104
|
-
source: this.STRATEGY_NAME,
|
|
105
|
-
timestamp: Date.now(),
|
|
106
|
-
data: data, // Explicit type assertion
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Remove the protection strategy
|
|
111
|
-
* Can be overridden by subclasses for custom cleanup
|
|
112
|
-
*/
|
|
113
|
-
remove() {
|
|
114
|
-
try {
|
|
115
|
-
if (!this.isAppliedFlag) {
|
|
116
|
-
this.log("Protection not applied");
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
// Unsubscribe from all events
|
|
120
|
-
if (this.mediator && this.subscriptionIds.length > 0) {
|
|
121
|
-
this.subscriptionIds.forEach((id) => {
|
|
122
|
-
this.mediator?.unsubscribe(id);
|
|
123
|
-
});
|
|
124
|
-
this.subscriptionIds = [];
|
|
125
|
-
this.log("Unsubscribed from all events");
|
|
126
|
-
}
|
|
127
|
-
if (isBrowser()) {
|
|
128
|
-
// Remove all event listeners using EventManager
|
|
129
|
-
const removedCount = this.removeEventsByOwner();
|
|
130
|
-
// Clear the event IDs array
|
|
131
|
-
this.eventIds = [];
|
|
132
|
-
this.isAppliedFlag = false;
|
|
133
|
-
this.log(`Protection removed (${removedCount} events)`);
|
|
134
|
-
// Publish event that strategy was removed
|
|
135
|
-
this.publishEvent(ProtectionEventType.STRATEGY_REMOVED);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
catch (error) {
|
|
139
|
-
this.handleError(StrategyErrorType.REMOVAL, "Failed to remove protection", error);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Check if the strategy is currently applied
|
|
144
|
-
*/
|
|
145
|
-
isApplied() {
|
|
146
|
-
return this.isAppliedFlag;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Update strategy options
|
|
150
|
-
* Should be implemented by subclasses that support options
|
|
151
|
-
*/
|
|
152
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
153
|
-
updateOptions(options) {
|
|
154
|
-
try {
|
|
155
|
-
// Default implementation just logs that the method is not implemented
|
|
156
|
-
this.log("Method updateOptions not implemented");
|
|
157
|
-
}
|
|
158
|
-
catch (error) {
|
|
159
|
-
this.handleError(StrategyErrorType.OPTION_UPDATE, "Failed to update options", error);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Get the debug mode status
|
|
164
|
-
*/
|
|
165
|
-
isDebugEnabled() {
|
|
166
|
-
return this.debugMode;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Set debug mode
|
|
170
|
-
*/
|
|
171
|
-
setDebugMode(enabled) {
|
|
172
|
-
this.debugMode = enabled;
|
|
173
|
-
this.log(`Debug mode ${enabled ? "enabled" : "disabled"}`);
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Handle an error that occurred in the strategy
|
|
177
|
-
* @param errorType Type of error
|
|
178
|
-
* @param message Error message
|
|
179
|
-
* @param originalError Original error that was caught
|
|
180
|
-
*/
|
|
181
|
-
handleError(errorType, message, originalError) {
|
|
182
|
-
const error = new StrategyError(this.STRATEGY_NAME, errorType, message, originalError);
|
|
183
|
-
if (this.debugMode) {
|
|
184
|
-
console.error(error);
|
|
185
|
-
if (error.originalError instanceof Error && error.originalError.stack) {
|
|
186
|
-
console.error("Original stack:", error.originalError.stack);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
console.error(error.message);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Log a debug message if debug mode is enabled
|
|
195
|
-
* @param message Message to log
|
|
196
|
-
* @param args Additional arguments to log
|
|
197
|
-
*/
|
|
198
|
-
log(message, ...args) {
|
|
199
|
-
if (this.debugMode) {
|
|
200
|
-
console.log(`${this.STRATEGY_NAME}: ${message}`, ...args);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Log a warning message
|
|
205
|
-
* @param message Warning message
|
|
206
|
-
* @param args Additional arguments to log
|
|
207
|
-
*/
|
|
208
|
-
warn(message, ...args) {
|
|
209
|
-
if (this.debugMode) {
|
|
210
|
-
console.warn(`${this.STRATEGY_NAME}: ${message}`, ...args);
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
// In non-debug mode, only log the message without args for brevity
|
|
214
|
-
console.warn(`${this.STRATEGY_NAME}: ${message}`);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Log an error message
|
|
219
|
-
* @param message Error message
|
|
220
|
-
* @param args Additional arguments to log
|
|
221
|
-
*/
|
|
222
|
-
error(message, ...args) {
|
|
223
|
-
console.error(`${this.STRATEGY_NAME}: ${message}`, ...args);
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Execute a function with error handling
|
|
227
|
-
* @param operation Name of the operation for error reporting
|
|
228
|
-
* @param errorType Type of error for categorization
|
|
229
|
-
* @param fn Function to execute
|
|
230
|
-
* @returns The result of the function or undefined if an error occurred
|
|
231
|
-
*/
|
|
232
|
-
safeExecute(operation, errorType, fn) {
|
|
233
|
-
try {
|
|
234
|
-
return fn();
|
|
235
|
-
}
|
|
236
|
-
catch (error) {
|
|
237
|
-
this.handleError(errorType, `Error during ${operation}`, error);
|
|
238
|
-
return undefined;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Execute an async function with error handling
|
|
243
|
-
* @param operation Name of the operation for error reporting
|
|
244
|
-
* @param errorType Type of error for categorization
|
|
245
|
-
* @param fn Async function to execute
|
|
246
|
-
* @returns Promise resolving to the result of the function or undefined if an error occurred
|
|
247
|
-
*/
|
|
248
|
-
async safeExecuteAsync(operation, errorType, fn) {
|
|
249
|
-
try {
|
|
250
|
-
return await fn();
|
|
251
|
-
}
|
|
252
|
-
catch (error) {
|
|
253
|
-
this.handleError(errorType, `Error during ${operation}`, error);
|
|
254
|
-
return undefined;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Register an event with the EventManager
|
|
259
|
-
* @param target The target element, document, or window
|
|
260
|
-
* @param eventType The type of event (e.g., "click", "keydown")
|
|
261
|
-
* @param handler The event handler function
|
|
262
|
-
* @param options Additional options for the event listener
|
|
263
|
-
* @returns The ID of the registered event
|
|
264
|
-
*/
|
|
265
|
-
registerEvent(target, eventType, handler, options) {
|
|
266
|
-
if (!target || !isBrowser())
|
|
267
|
-
return "";
|
|
268
|
-
try {
|
|
269
|
-
// Create a wrapped handler that includes error handling
|
|
270
|
-
const wrappedHandler = (event) => {
|
|
271
|
-
try {
|
|
272
|
-
return handler(event);
|
|
273
|
-
}
|
|
274
|
-
catch (error) {
|
|
275
|
-
this.handleError(StrategyErrorType.EVENT_HANDLING, `Error handling ${eventType} event`, error);
|
|
276
|
-
}
|
|
277
|
-
};
|
|
278
|
-
// Pass all options including priority to the eventManager
|
|
279
|
-
const eventId = eventManager.addEventListener(target, eventType, wrappedHandler, this.STRATEGY_NAME, options);
|
|
280
|
-
if (eventId) {
|
|
281
|
-
this.eventIds.push(eventId);
|
|
282
|
-
this.log(`Registered ${eventType} event (ID: ${eventId})`);
|
|
283
|
-
}
|
|
284
|
-
return eventId;
|
|
285
|
-
}
|
|
286
|
-
catch (error) {
|
|
287
|
-
this.handleError(StrategyErrorType.EVENT_HANDLING, `Failed to register ${eventType} event`, error);
|
|
288
|
-
return "";
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Remove all event listeners for this strategy
|
|
293
|
-
* @returns The number of events removed
|
|
294
|
-
*/
|
|
295
|
-
removeEventsByOwner() {
|
|
296
|
-
try {
|
|
297
|
-
const removedCount = eventManager.removeEventsByOwner(this.STRATEGY_NAME);
|
|
298
|
-
if (removedCount > 0) {
|
|
299
|
-
this.log(`Removed ${removedCount} events by owner ID`);
|
|
300
|
-
}
|
|
301
|
-
return removedCount;
|
|
302
|
-
}
|
|
303
|
-
catch (error) {
|
|
304
|
-
this.handleError(StrategyErrorType.REMOVAL, "Failed to remove events by owner", error);
|
|
305
|
-
return 0;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Remove all event listeners for a specific target
|
|
310
|
-
* @param target The target to remove events from
|
|
311
|
-
* @returns The number of events removed
|
|
312
|
-
*/
|
|
313
|
-
removeAllEventsForTarget(target) {
|
|
314
|
-
if (!target || !isBrowser())
|
|
315
|
-
return 0;
|
|
316
|
-
try {
|
|
317
|
-
const removedCount = eventManager.removeAllEventsForTarget(target);
|
|
318
|
-
if (removedCount > 0) {
|
|
319
|
-
this.log(`Removed ${removedCount} events from target`);
|
|
320
|
-
}
|
|
321
|
-
return removedCount;
|
|
322
|
-
}
|
|
323
|
-
catch (error) {
|
|
324
|
-
this.handleError(StrategyErrorType.REMOVAL, "Failed to remove events for target", error);
|
|
325
|
-
return 0;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Remove event listeners by CSS selector
|
|
330
|
-
* @param selector CSS selector to match elements
|
|
331
|
-
* @param eventType Type of event to remove
|
|
332
|
-
* @returns The number of events removed
|
|
333
|
-
*/
|
|
334
|
-
removeEventsBySelector(selector, eventType) {
|
|
335
|
-
if (!isBrowser())
|
|
336
|
-
return 0;
|
|
337
|
-
try {
|
|
338
|
-
const removedCount = eventManager.removeEventsBySelector(selector, eventType, this.STRATEGY_NAME);
|
|
339
|
-
if (removedCount > 0) {
|
|
340
|
-
this.log(`Removed ${removedCount} ${eventType} events via selector "${selector}"`);
|
|
341
|
-
}
|
|
342
|
-
return removedCount;
|
|
343
|
-
}
|
|
344
|
-
catch (error) {
|
|
345
|
-
this.handleError(StrategyErrorType.REMOVAL, `Failed to remove events by selector "${selector}"`, error);
|
|
346
|
-
return 0;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import type { CustomEventHandlers, DevToolsOptions } from "../types";
|
|
2
|
-
import { AbstractStrategy } from "./AbstractStrategy";
|
|
3
|
-
/**
|
|
4
|
-
* Strategy for detecting and responding to DevTools usage
|
|
5
|
-
*/
|
|
6
|
-
export declare class DevToolsStrategy extends AbstractStrategy {
|
|
7
|
-
private intervalId;
|
|
8
|
-
private taskId;
|
|
9
|
-
private customHandler?;
|
|
10
|
-
private isDevToolsOpen;
|
|
11
|
-
private targetElement;
|
|
12
|
-
private options;
|
|
13
|
-
private contentManager;
|
|
14
|
-
private overlayManager;
|
|
15
|
-
private resizeEventId;
|
|
16
|
-
private originalWidth;
|
|
17
|
-
private originalHeight;
|
|
18
|
-
private resizeHandler;
|
|
19
|
-
private previousOrientation;
|
|
20
|
-
/**
|
|
21
|
-
* Create a new DevToolsStrategy
|
|
22
|
-
* @param options Options for customizing the DevTools protection
|
|
23
|
-
* @param targetElement Element containing sensitive content
|
|
24
|
-
* @param customHandler Optional custom handler for DevTools detection
|
|
25
|
-
* @param debugMode Enable debug mode for troubleshooting
|
|
26
|
-
*/
|
|
27
|
-
constructor(options?: DevToolsOptions, targetElement?: HTMLElement | null, customHandler?: CustomEventHandlers["onDevToolsOpen"], debugMode?: boolean);
|
|
28
|
-
/**
|
|
29
|
-
* Detect if DevTools is open based on window dimensions
|
|
30
|
-
* @returns True if DevTools is likely open, false otherwise
|
|
31
|
-
*/
|
|
32
|
-
private detectDevTools;
|
|
33
|
-
/**
|
|
34
|
-
* Handle window resize events to detect DevTools
|
|
35
|
-
*/
|
|
36
|
-
private handleResize;
|
|
37
|
-
/**
|
|
38
|
-
* Start monitoring for DevTools usage
|
|
39
|
-
*/
|
|
40
|
-
private startMonitoring;
|
|
41
|
-
/**
|
|
42
|
-
* Apply DevTools protection by creating overlay and event blocker
|
|
43
|
-
*/
|
|
44
|
-
private applyDevToolsProtection;
|
|
45
|
-
/**
|
|
46
|
-
* Hide sensitive content when DevTools is open
|
|
47
|
-
*/
|
|
48
|
-
private hideSensitiveContent;
|
|
49
|
-
/**
|
|
50
|
-
* Restore sensitive content when DevTools is closed
|
|
51
|
-
*/
|
|
52
|
-
private restoreSensitiveContent;
|
|
53
|
-
/**
|
|
54
|
-
* Remove DevTools protection
|
|
55
|
-
*/
|
|
56
|
-
private removeDevToolsProtection;
|
|
57
|
-
/**
|
|
58
|
-
* Apply the protection strategy
|
|
59
|
-
*/
|
|
60
|
-
apply(): void;
|
|
61
|
-
/**
|
|
62
|
-
* Remove the protection strategy
|
|
63
|
-
* Override the base implementation to handle additional cleanup
|
|
64
|
-
*/
|
|
65
|
-
remove(): void;
|
|
66
|
-
/**
|
|
67
|
-
* Update DevTools protection options
|
|
68
|
-
* @param options New options
|
|
69
|
-
*/
|
|
70
|
-
updateOptions(options: Record<string, unknown>): void;
|
|
71
|
-
/**
|
|
72
|
-
* Set debug mode
|
|
73
|
-
* @param enabled Whether debug mode should be enabled
|
|
74
|
-
*/
|
|
75
|
-
setDebugMode(enabled: boolean): void;
|
|
76
|
-
/**
|
|
77
|
-
* Check if strategy is applied
|
|
78
|
-
*/
|
|
79
|
-
isApplied(): boolean;
|
|
80
|
-
/**
|
|
81
|
-
* Check if debug mode is enabled
|
|
82
|
-
* @returns True if debug mode is enabled
|
|
83
|
-
*/
|
|
84
|
-
isDebugEnabled(): boolean;
|
|
85
|
-
}
|