Files
bom-local-service/Services/Interfaces/IBrowserService.cs
T
alex ffd3636d1c Remove minutes ago parsing, use UTC timestamps directly
- Refactor TimeParsingService to parse time strings to UTC only
- Remove minutesAgo from RadarFrame and FrameMetadata models
- Update CaptureFramesStep to extract UTC timestamps directly
- Update CacheService to store/load ObservationTime instead of MinutesAgo
- Update BomRadarService to use AbsoluteObservationTime directly
- Remove all backward compatibility code for old cache folders
- Update documentation and test SPA to calculate minutes ago on client
- Fix step registration to register concrete types for DI resolution
- Fix hosted service registration to use reflection correctly
2025-12-23 21:52:42 +10:00

46 lines
2.2 KiB
C#

using BomLocalService.Services.Interfaces.Registration;
using Microsoft.Playwright;
namespace BomLocalService.Services.Interfaces;
/// <summary>
/// Service interface for managing Playwright browser instances and automation.
/// Handles browser lifecycle, context creation, and anti-detection measures for web scraping.
/// </summary>
public interface IBrowserService : ISingletonService, IDisposable
{
/// <summary>
/// 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.
/// </summary>
/// <returns>A configured browser context ready for page creation</returns>
Task<IBrowserContext> CreateContextAsync();
/// <summary>
/// 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.
/// </summary>
/// <param name="context">The browser context to create the page in</param>
/// <param name="requestId">Unique request identifier for debug file organization</param>
/// <returns>Tuple containing the page, list of console messages, and list of network requests</returns>
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);
/// <summary>
/// Initializes and pre-warms the browser instance.
/// Launches the Chromium browser to reduce latency on first use.
/// </summary>
/// <param name="cancellationToken">Cancellation token to cancel the operation</param>
Task InitializeAsync(CancellationToken cancellationToken = default);
/// <summary>
/// Gets the semaphore used to synchronize browser operations.
/// Ensures only one browser operation runs at a time to prevent resource conflicts.
/// </summary>
/// <returns>The semaphore for synchronizing browser access</returns>
SemaphoreSlim GetSemaphore();
}