using Microsoft.Playwright; namespace BomLocalService.Services.Interfaces; /// /// Service interface for managing Playwright browser instances and automation. /// Handles browser lifecycle, context creation, and anti-detection measures for web scraping. /// public interface IBrowserService : IDisposable { /// /// Creates a new browser context with proper configuration for BOM website scraping. /// Configures viewport, user agent, timezone, and HTTP headers to mimic a real browser. /// /// A configured browser context ready for page creation Task CreateContextAsync(); /// /// Creates a new page with anti-detection scripts and optional debug event handlers. /// Injects comprehensive anti-detection JavaScript to avoid bot detection. /// If debug mode is enabled, captures console messages and network requests for debugging. /// /// The browser context to create the page in /// Unique request identifier for debug file organization /// Tuple containing the page, list of console messages, and list of network requests Task<(IPage page, List<(string type, string text, DateTime timestamp)> consoleMessages, List<(string method, string url, int? status, string resourceType, DateTime timestamp)> networkRequests)> CreatePageWithDebugAsync( IBrowserContext context, string requestId); /// /// Initializes and pre-warms the browser instance. /// Launches the Chromium browser to reduce latency on first use. /// /// Cancellation token to cancel the operation Task InitializeAsync(CancellationToken cancellationToken = default); /// /// Gets the semaphore used to synchronize browser operations. /// Ensures only one browser operation runs at a time to prevent resource conflicts. /// /// The semaphore for synchronizing browser access SemaphoreSlim GetSemaphore(); }