load method

Future<bool> load({
  1. bool useCache = true,
})

Loads HTML content from the specified URL with retry support and caching.

Returns true if successful, throws appropriate exceptions on failure.

Throws:

Implementation

Future<bool> load({bool useCache = true}) async {
  _loadCompleter = Completer<void>();

  try {
    // Check cache first if enabled
    if (useCache) {
      final cachedContent = await _cacheManager.get(url);
      if (cachedContent != null) {
        _htmlContent = cachedContent;
        _loadCompleter?.complete();
        return true;
      }
    }

    // Load from network
    final response = await _loadWithRetry();

    // Check content size
    final contentLength = response.contentLength ?? response.bodyBytes.length;
    if (contentLength > config.maxContentSize) {
      throw ContentTooLargeException(contentLength, config.maxContentSize);
    }

    // Handle different encodings
    _htmlContent = _decodeResponse(response);

    // Cache the content if enabled
    if (useCache && _htmlContent != null) {
      await _cacheManager.set(url, _htmlContent!);
    }

    _loadCompleter?.complete();
    return true;
  } catch (e) {
    _loadCompleter?.completeError(e);
    rethrow;
  }
}