import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

// 全局错误处理 - 过滤浏览器扩展错误
window.addEventListener('error', (event) => {
  // 过滤掉扩展相关的错误
  if (event.filename && (
    event.filename.includes('content_scripts') ||
    event.filename.includes('extension') ||
    event.filename.includes('chrome-extension') ||
    event.filename.includes('moz-extension')
  )) {
    event.preventDefault();
    console.warn('浏览器扩展错误已忽略:', event.message);
    return false;
  }
});

// 处理未捕获的 Promise 错误
window.addEventListener('unhandledrejection', (event) => {
  const errorMessage = event.reason?.message || event.reason?.toString() || '';
  if (errorMessage.includes('shadowRoot') || 
      errorMessage.includes('content_scripts') ||
      errorMessage.includes('extension')) {
    event.preventDefault();
    console.warn('浏览器扩展 Promise 错误已忽略:', event.reason);
    return false;
  }
});

const root = ReactDOM.createRoot(
  document.getElementById('root') as HTMLElement
);
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
