humanbehavior-js 0.4.10 → 0.4.12

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.
@@ -45,6 +45,7 @@ declare class HumanBehaviorTracker {
45
45
  logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
46
46
  redactFields?: string[];
47
47
  enableAutomaticTracking?: boolean;
48
+ suppressConsoleErrors?: boolean;
48
49
  automaticTrackingOptions?: {
49
50
  trackButtons?: boolean;
50
51
  trackLinks?: boolean;
@@ -135,6 +135,7 @@ declare class HumanBehaviorTracker {
135
135
  logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
136
136
  redactFields?: string[];
137
137
  enableAutomaticTracking?: boolean;
138
+ suppressConsoleErrors?: boolean;
138
139
  automaticTrackingOptions?: {
139
140
  trackButtons?: boolean;
140
141
  trackLinks?: boolean;
@@ -47,6 +47,7 @@ declare class HumanBehaviorTracker {
47
47
  logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
48
48
  redactFields?: string[];
49
49
  enableAutomaticTracking?: boolean;
50
+ suppressConsoleErrors?: boolean;
50
51
  automaticTrackingOptions?: {
51
52
  trackButtons?: boolean;
52
53
  trackLinks?: boolean;
@@ -48,6 +48,7 @@ declare class HumanBehaviorTracker {
48
48
  logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
49
49
  redactFields?: string[];
50
50
  enableAutomaticTracking?: boolean;
51
+ suppressConsoleErrors?: boolean;
51
52
  automaticTrackingOptions?: {
52
53
  trackButtons?: boolean;
53
54
  trackLinks?: boolean;
@@ -45,6 +45,7 @@ declare class HumanBehaviorTracker {
45
45
  logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
46
46
  redactFields?: string[];
47
47
  enableAutomaticTracking?: boolean;
48
+ suppressConsoleErrors?: boolean;
48
49
  automaticTrackingOptions?: {
49
50
  trackButtons?: boolean;
50
51
  trackLinks?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "humanbehavior-js",
3
- "version": "0.4.10",
3
+ "version": "0.4.12",
4
4
  "description": "SDK for HumanBehavior session and event recording",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
package/readme.md CHANGED
@@ -36,8 +36,9 @@ For the best session continuity experience, use the SPA approach:
36
36
  <script>
37
37
  // Initialize once - session persists across all navigation
38
38
  const tracker = HumanBehaviorTracker.init('your-api-key', {
39
- logLevel: 'debug',
40
- redactFields: ['password', 'credit_card']
39
+ logLevel: 'warn', // Reduce console noise
40
+ redactFields: ['password', 'credit_card'],
41
+ suppressConsoleErrors: true // Suppress common rrweb errors (default)
41
42
  });
42
43
 
43
44
  // Your SPA navigation logic here
@@ -84,6 +85,7 @@ const tracker = HumanBehaviorTracker.init(apiKey, options);
84
85
  - `ingestionUrl`: Custom ingestion server URL
85
86
  - `logLevel`: 'none' | 'error' | 'warn' | 'info' | 'debug'
86
87
  - `redactFields`: Array of CSS selectors to redact
88
+ - `suppressConsoleErrors`: Boolean to suppress common rrweb errors (default: true)
87
89
 
88
90
  ### Session Management
89
91
 
@@ -131,6 +133,28 @@ tracker.viewLogs();
131
133
  const status = tracker.getConnectionStatus();
132
134
  ```
133
135
 
136
+ ### Error Suppression
137
+
138
+ The SDK automatically suppresses common rrweb errors for a clean console:
139
+
140
+ ```javascript
141
+ // Enable error suppression (default)
142
+ const tracker = HumanBehaviorTracker.init('your-api-key', {
143
+ suppressConsoleErrors: true // Suppresses canvas security errors, CORS issues, etc.
144
+ });
145
+
146
+ // Disable error suppression for debugging
147
+ const tracker = HumanBehaviorTracker.init('your-api-key', {
148
+ suppressConsoleErrors: false // Show all errors for debugging
149
+ });
150
+ ```
151
+
152
+ **Suppressed Errors:**
153
+ - Canvas security errors (`SecurityError: Failed to execute 'toDataURL'`)
154
+ - Cross-origin resource errors
155
+ - CORS policy violations
156
+ - Ad blocker interference warnings
157
+
134
158
  ## Session Continuity
135
159
 
136
160
  The SDK automatically handles session continuity:
package/src/tracker.ts CHANGED
@@ -60,6 +60,7 @@ export class HumanBehaviorTracker {
60
60
  logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
61
61
  redactFields?: string[];
62
62
  enableAutomaticTracking?: boolean;
63
+ suppressConsoleErrors?: boolean; // New option to control error suppression
63
64
  automaticTrackingOptions?: {
64
65
  trackButtons?: boolean;
65
66
  trackLinks?: boolean;
@@ -68,6 +69,61 @@ export class HumanBehaviorTracker {
68
69
  includeClasses?: boolean;
69
70
  };
70
71
  }): HumanBehaviorTracker {
72
+ // ✅ SUPPRESS COMMON RRWEB ERRORS FOR CLEAN CONSOLE
73
+ if (isBrowser && options?.suppressConsoleErrors !== false) {
74
+ // Suppress canvas security errors
75
+ const originalConsoleError = console.error;
76
+ console.error = (...args: any[]) => {
77
+ const message = args.join(' ');
78
+ if (
79
+ message.includes('SecurityError: Failed to execute \'toDataURL\'') ||
80
+ message.includes('Tainted canvases may not be exported') ||
81
+ message.includes('Cannot inline img src=') ||
82
+ message.includes('Cross-Origin') ||
83
+ message.includes('CORS') ||
84
+ message.includes('Access-Control-Allow-Origin') ||
85
+ message.includes('Failed to load resource') ||
86
+ message.includes('net::ERR_BLOCKED_BY_CLIENT')
87
+ ) {
88
+ // Silently suppress these common rrweb errors
89
+ return;
90
+ }
91
+ originalConsoleError.apply(console, args);
92
+ };
93
+
94
+ // Suppress console.warn for similar issues
95
+ const originalConsoleWarn = console.warn;
96
+ console.warn = (...args: any[]) => {
97
+ const message = args.join(' ');
98
+ if (
99
+ message.includes('Cannot inline img src=') ||
100
+ message.includes('Cross-Origin') ||
101
+ message.includes('CORS') ||
102
+ message.includes('Access-Control-Allow-Origin') ||
103
+ message.includes('Failed to load resource') ||
104
+ message.includes('net::ERR_BLOCKED_BY_CLIENT')
105
+ ) {
106
+ // Silently suppress these common rrweb warnings
107
+ return;
108
+ }
109
+ originalConsoleWarn.apply(console, args);
110
+ };
111
+
112
+ // Add global error handler for any remaining rrweb errors
113
+ window.addEventListener('error', (event) => {
114
+ const message = event.message || '';
115
+ if (
116
+ message.includes('SecurityError') ||
117
+ message.includes('Tainted canvases') ||
118
+ message.includes('toDataURL') ||
119
+ message.includes('Cross-Origin') ||
120
+ message.includes('CORS')
121
+ ) {
122
+ event.preventDefault();
123
+ return false;
124
+ }
125
+ });
126
+ }
71
127
  // Return existing instance if already initialized
72
128
  if (isBrowser && window.__humanBehaviorGlobalTracker) {
73
129
  logDebug('Tracker already initialized, returning existing instance');
@@ -94,17 +150,6 @@ export class HumanBehaviorTracker {
94
150
  tracker.setupAutomaticTracking(options?.automaticTrackingOptions);
95
151
  }
96
152
 
97
- // Test connection (non-blocking)
98
- if (isBrowser) {
99
- const testUrl = tracker.api['baseUrl'] + '/api/health';
100
- fetch(testUrl, { method: 'HEAD' })
101
- .then(() => logDebug('Connection test successful'))
102
- .catch((error) => {
103
- logWarn('Connection test failed - ad blocker may be active:', error.message);
104
- tracker._connectionBlocked = true;
105
- });
106
- }
107
-
108
153
  // Start tracking
109
154
  tracker.start();
110
155
 
@@ -792,12 +837,11 @@ export class HumanBehaviorTracker {
792
837
  maskInputOptions: { password: true }, // HumanBehavior default
793
838
  maskInputFn: undefined,
794
839
  slimDOMOptions: {},
795
- collectFonts: false, // HumanBehavior default
796
- inlineStylesheet: true, // HumanBehavior default
797
- recordCrossOriginIframes: false, // HumanBehavior default
798
-
799
- // CANVAS RECORDING - Disabled to prevent large data URIs
800
- recordCanvas: false, // Disabled to prevent large data URIs
840
+ // ERROR SUPPRESSION SETTINGS - Disabled to prevent console noise
841
+ collectFonts: false, // Disable font collection to reduce errors
842
+ inlineStylesheet: true, // Keep styles for proper session replay
843
+ recordCrossOriginIframes: false, // Prevent cross-origin iframe errors
844
+ recordCanvas: false, // Disabled to prevent large data URIs and canvas errors
801
845
 
802
846
  // ✅ FULLSNAPSHOT GENERATION - No periodic snapshots to avoid animation issues
803
847
  // Rely on initial FullSnapshot + navigation-triggered ones only