waitForDomContentLoaded method
Waits for the DOM content to be loaded
Implementation
Future<bool> waitForDomContentLoaded({int timeoutMillis = 30000}) async {
_checkDisposed();
if (_controller == null) {
throw ScrapingException.validation(
'Browser not initialized',
isRetryable: false,
);
}
try {
final result = await _controller!.evaluateJavascript(
source: """
new Promise((resolve) => {
if (document.readyState === 'complete' || document.readyState === 'interactive') {
resolve(true);
} else {
document.addEventListener('DOMContentLoaded', () => resolve(true));
}
});
""",
);
return result == true;
} catch (e) {
_log('Error waiting for DOM content loaded: $e', isError: true);
return false;
}
}