"""
Browser configuration constants from browser-use.
Source: https://github.com/browser-use/browser-use/blob/main/browser_use/browser/profile.py

This file contains only the Chrome arguments and disabled features needed for anti-detection.
Keep this in sync with browser-use for best compatibility.
"""

# 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)
]
