viewpoint_core/wait/load_state/mod.rs
1//! Document load state types.
2
3/// Document load states for navigation waiting.
4///
5/// These states are compatible with Playwright's load states and occur
6/// in the following order: Commit → `DomContentLoaded` → Load → `NetworkIdle`
7#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
8pub enum DocumentLoadState {
9 /// Navigation response received (first byte).
10 /// This is the earliest state and completes when the server starts sending a response.
11 Commit,
12
13 /// DOM fully parsed (`DOMContentLoaded` event fired).
14 /// The HTML document has been completely loaded and parsed.
15 DomContentLoaded,
16
17 /// Full page load complete (load event fired).
18 /// All resources including images, stylesheets, and scripts have loaded.
19 /// This is the default wait state.
20 #[default]
21 Load,
22
23 /// No network requests for 500ms.
24 /// Useful for pages with dynamic content that loads after the initial page load.
25 NetworkIdle,
26}
27
28impl DocumentLoadState {
29 /// Check if this state has been reached given the current state.
30 ///
31 /// Returns `true` if `current` is at or past `self` in the load order.
32 pub fn is_reached(&self, current: Self) -> bool {
33 current >= *self
34 }
35
36 /// Get the CDP event name associated with this state.
37 pub fn cdp_event_name(&self) -> Option<&'static str> {
38 match self {
39 // Commit is handled via network response, NetworkIdle requires custom tracking
40 Self::Commit | Self::NetworkIdle => None,
41 Self::DomContentLoaded => Some("Page.domContentEventFired"),
42 Self::Load => Some("Page.loadEventFired"),
43 }
44 }
45}
46
47#[cfg(test)]
48mod tests;