File size: 2,957 Bytes
b190b45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**

 * Error Suppressor - Suppress external service errors (Hugging Face Spaces, SSE, etc.)

 * This prevents console pollution from external services that we don't control

 */

(function() {
  'use strict';

  // Store original console methods
  const originalError = console.error;
  const originalWarn = console.warn;

  // Patterns to suppress
  const suppressedPatterns = [
    // SSE errors from Hugging Face Spaces
    /Failed to fetch.*via SSE/i,
    /SSE Stream ended with error/i,
    /BodyStreamBuffer was aborted/i,
    /SpaceHeader.*\.js/i,
    /AbortError.*BodyStreamBuffer/i,
    
    // Permissions-Policy warnings (harmless browser warnings)
    /Unrecognized feature.*permissions-policy/i,
    /Unrecognized feature: 'ambient-light-sensor'/i,
    /Unrecognized feature: 'battery'/i,
    /Unrecognized feature: 'document-domain'/i,
    /Unrecognized feature: 'layout-animations'/i,
    /Unrecognized feature: 'legacy-image-formats'/i,
    /Unrecognized feature: 'oversized-images'/i,
    /Unrecognized feature: 'vr'/i,
    /Unrecognized feature: 'wake-lock'/i,
    
    // Other harmless external service errors
    /index\.js.*SSE/i,
    /onStateChange.*SSE/i
  ];

  /**

   * Check if a message should be suppressed

   */
  function shouldSuppress(message) {
    if (!message) return false;
    
    const messageStr = typeof message === 'string' ? message : String(message);
    
    return suppressedPatterns.some(pattern => {
      try {
        return pattern.test(messageStr);
      } catch (e) {
        return false;
      }
    });
  }

  /**

   * Filter console.error

   */
  console.error = function(...args) {
    const message = args[0];
    
    // Suppress external service errors
    if (shouldSuppress(message)) {
      return; // Silently ignore
    }
    
    // Call original error handler
    originalError.apply(console, args);
  };

  /**

   * Filter console.warn

   */
  console.warn = function(...args) {
    const message = args[0];
    
    // Suppress Permissions-Policy warnings
    if (shouldSuppress(message)) {
      return; // Silently ignore
    }
    
    // Call original warn handler
    originalWarn.apply(console, args);
  };

  // Also catch unhandled errors from external scripts
  window.addEventListener('error', function(event) {
    if (shouldSuppress(event.message)) {
      event.preventDefault();
      event.stopPropagation();
      return false;
    }
  }, true);

  // Suppress unhandled promise rejections from external services
  window.addEventListener('unhandledrejection', function(event) {
    const reason = event.reason;
    const message = reason?.message || reason?.toString() || '';
    
    if (shouldSuppress(message)) {
      event.preventDefault();
      return false;
    }
  });

  console.log('[Error Suppressor] External service error filtering enabled');
})();