"""
Purpose: Centralize the Chrome flag set used to launch Playwright in an anti-detection configuration mirroring the browser-use project, so BrowserAutomation looks like a normal browser to bot-detection.
LLM-Note:
  Dependencies: pure data, no imports | imported by [useful_tools/browser_tools/browser.py (passes CHROME_DEFAULT_ARGS / IGNORE_DEFAULT_ARGS to playwright.chromium.launch)] | no direct tests (behavior covered by tests/cli/test_browser_agent.py)
  Data flow: module-level constants only — read once when BrowserAutomation builds launch options
  Integration: exposes CHROME_DISABLED_COMPONENTS (list[str], joined into --disable-features=…), CHROME_DEFAULT_ARGS (list[str], passed as launch args; ends with the disabled-features flag), IGNORE_DEFAULT_ARGS (list[str], removed from Playwright's defaults)
  State/Effects: none
  Errors: none
NOTE: Keep in sync with https://github.com/browser-use/browser-use/blob/main/browser_use/browser/profile.py — drift here is what causes anti-detection regressions.
Source: https://github.com/browser-use/browser-use/blob/main/browser_use/browser/profile.py
"""

# Chrome disabled components/features
# These are passed via --disable-features={list}
CHROME_DISABLED_COMPONENTS = [
    'AcceptCHFrame',
    'AutoExpandDetailsElement',
    'AvoidUnnecessaryBeforeUnloadCheckSync',
    'CertificateTransparencyComponentUpdater',
    'DestroyProfileOnBrowserClose',
    'DialMediaRouteProvider',
    'ExtensionManifestV2Disabled',
    'GlobalMediaControls',
    'HttpsUpgrades',
    'ImprovedCookieControls',
    'LazyFrameLoading',
    'LensOverlay',
    'MediaRouter',
    'PaintHolding',
    'ThirdPartyStoragePartitioning',
    'Translate',
    # Added by browser-use:
    'AutomationControlled',  # KEY: Removes navigator.webdriver
    'BackForwardCache',
    'OptimizationHints',
    'ProcessPerSiteUpToMainFrameThreshold',
    'InterestFeedContentSuggestions',
    'CalculateNativeWinOcclusion',
    'HeavyAdPrivacyMitigations',
    'PrivacySandboxSettings4',
    'AutofillServerCommunication',
    'CrashReporting',
    'OverscrollHistoryNavigation',
    'InfiniteSessionRestore',
    'ExtensionDisableUnsupportedDeveloper',
    'ExtensionManifestV2Unsupported',
]

# Chrome default arguments (53 args)
CHROME_DEFAULT_ARGS = [
    '--disable-field-trial-config',
    '--disable-background-networking',
    '--disable-background-timer-throttling',
    '--disable-backgrounding-occluded-windows',
    '--disable-back-forward-cache',
    '--disable-breakpad',
    '--disable-client-side-phishing-detection',
    '--disable-component-extensions-with-background-pages',
    '--disable-component-update',
    '--no-default-browser-check',
    '--disable-dev-shm-usage',
    '--disable-hang-monitor',
    '--disable-ipc-flooding-protection',
    '--disable-popup-blocking',
    '--disable-prompt-on-repost',
    '--disable-renderer-backgrounding',
    '--metrics-recording-only',
    '--no-first-run',
    '--no-service-autorun',
    '--export-tagged-pdf',
    '--disable-search-engine-choice-screen',
    '--unsafely-disable-devtools-self-xss-warnings',
    '--enable-features=NetworkService,NetworkServiceInProcess',
    '--enable-network-information-downlink-max',
    '--test-type=gpu',
    '--disable-sync',
    '--allow-legacy-extension-manifests',
    '--allow-pre-commit-input',
    '--disable-blink-features=AutomationControlled',  # KEY: anti-detection
    '--install-autogenerated-theme=0,0,0',
    '--log-level=2',
    '--disable-focus-on-load',
    '--disable-window-activation',
    '--generate-pdf-document-outline',
    '--no-pings',
    '--ash-no-nudges',
    '--disable-infobars',
    '--simulate-outdated-no-au="Tue, 31 Dec 2099 23:59:59 GMT"',
    '--hide-crash-restore-bubble',
    '--suppress-message-center-popups',
    '--disable-domain-reliability',
    '--disable-datasaver-prompt',
    '--disable-speech-synthesis-api',
    '--disable-speech-api',
    '--disable-print-preview',
    '--safebrowsing-disable-auto-update',
    '--disable-external-intent-requests',
    '--disable-desktop-notifications',
    '--noerrdialogs',
    '--silent-debugger-extension-api',
    '--disable-extensions-http-throttling',
    '--extensions-on-chrome-urls',
    '--disable-default-apps',
    f'--disable-features={",".join(CHROME_DISABLED_COMPONENTS)}',
]

# Arguments to ignore from Playwright defaults
# These are automation markers we DON'T want
IGNORE_DEFAULT_ARGS = [
    '--enable-automation',  # DON'T add this flag (anti-detection)
    '--disable-extensions',  # Allow extensions (looks more human)
    '--hide-scrollbars',     # Show scrollbars (more human-like)
]
