1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
//! # Viewpoint Core - Browser Automation Library
//!
//! Core domain types for `Viewpoint` browser automation, providing a Playwright-inspired
//! API for controlling Chromium-based browsers via the Chrome DevTools Protocol (CDP).
//!
//! This crate provides the high-level API for browser automation,
//! including [`Browser`], [`BrowserContext`], [`Page`], and navigation types.
//!
//! ## Features
//!
//! - **Browser Control**: Launch or connect to Chromium browsers
//! - **Page Navigation**: Navigate pages and wait for load states
//! - **Element Interaction**: Click, type, and interact with page elements via [`Locator`]
//! - **Network Interception**: Route, modify, and mock network requests
//! - **Device Emulation**: Emulate mobile devices, geolocation, and media features
//! - **Input Devices**: Keyboard, mouse, and touchscreen control
//! - **Screenshots & PDF**: Capture screenshots and generate PDFs
//! - **Clock Mocking**: Control time in tests with [`Clock`]
//! - **Event Handling**: Dialogs, downloads, file choosers, console messages
//! - **Tracing**: Record traces for debugging
//! - **Video Recording**: Record page interactions as video
//!
//! ## Quick Start
//!
//! ```no_run
//! use viewpoint_core::{Browser, DocumentLoadState};
//!
//! # async fn example() -> Result<(), viewpoint_core::CoreError> {
//! // Launch a browser and create a new context and page
//! let browser = Browser::launch()
//! .headless(true)
//! .launch()
//! .await?;
//!
//! let context = browser.new_context().await?;
//! let page = context.new_page().await?;
//!
//! // Navigate to a page
//! page.goto("https://example.com").goto().await?;
//!
//! // Interact with elements
//! page.locator("button#submit").click().await?;
//!
//! // Fill a form
//! page.locator("input[name='email']").fill("user@example.com").await?;
//!
//! // Get text content
//! let text = page.locator("h1").text_content().await?;
//! println!("Page title: {:?}", text);
//! # Ok(())
//! # }
//! ```
//!
//! ## Browser Connection Methods
//!
//! There are three ways to get a [`Browser`] instance:
//!
//! ```no_run
//! use viewpoint_core::Browser;
//! use std::time::Duration;
//!
//! # async fn example() -> Result<(), viewpoint_core::CoreError> {
//! // 1. Launch a new browser process
//! let browser = Browser::launch()
//! .headless(true)
//! .launch()
//! .await?;
//!
//! // 2. Connect via WebSocket URL (for pre-configured connections)
//! let browser = Browser::connect("ws://localhost:9222/devtools/browser/...").await?;
//!
//! // 3. Connect via HTTP endpoint (auto-discovers WebSocket URL)
//! let browser = Browser::connect_over_cdp("http://localhost:9222")
//! .timeout(Duration::from_secs(10))
//! .connect()
//! .await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Element Locators
//!
//! The [`Locator`] API provides auto-waiting and retry logic for robust element interaction:
//!
//! ```no_run
//! use viewpoint_core::{Browser, AriaRole};
//!
//! # async fn example() -> Result<(), viewpoint_core::CoreError> {
//! # let browser = Browser::launch().headless(true).launch().await?;
//! # let context = browser.new_context().await?;
//! # let page = context.new_page().await?;
//! // CSS selector
//! page.locator("button.primary").click().await?;
//!
//! // Text selector
//! page.get_by_text("Submit").click().await?;
//!
//! // Role selector (accessibility)
//! page.get_by_role(AriaRole::Button)
//! .with_name("Submit")
//! .build()
//! .click()
//! .await?;
//!
//! // Test ID selector (recommended for stable tests)
//! page.get_by_test_id("submit-button").click().await?;
//!
//! // Label selector (for form fields)
//! page.get_by_label("Email address").fill("test@example.com").await?;
//!
//! // Placeholder selector
//! page.get_by_placeholder("Enter your name").fill("John Doe").await?;
//!
//! // Chained locators
//! page.locator(".form")
//! .locator("input")
//! .first()
//! .fill("value")
//! .await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Network Interception
//!
//! Intercept and modify network requests using [`Route`]:
//!
//! ```ignore
//! use viewpoint_core::{Browser, Route};
//!
//! # async fn example() -> Result<(), viewpoint_core::CoreError> {
//! # let browser = Browser::launch().headless(true).launch().await?;
//! # let context = browser.new_context().await?;
//! # let page = context.new_page().await?;
//! // Block images
//! page.route("**/*.{png,jpg,jpeg,gif}", |route| {
//! async move { route.abort().await }
//! }).await?;
//!
//! // Mock an API response
//! page.route("**/api/users", |route| {
//! async move {
//! route.fulfill()
//! .status(200)
//! .content_type("application/json")
//! .body(r#"{"users": []}"#)
//! .fulfill()
//! .await
//! }
//! }).await?;
//!
//! // Modify requests
//! page.route("**/api/**", |route| {
//! async move {
//! route.continue_route()
//! .header("X-Custom-Header", "value")
//! .continue_route()
//! .await
//! }
//! }).await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Device Emulation
//!
//! Emulate mobile devices and other capabilities:
//!
//! ```no_run
//! use viewpoint_core::{Browser, Permission, ViewportSize};
//!
//! # async fn example() -> Result<(), viewpoint_core::CoreError> {
//! # let browser = Browser::launch().headless(true).launch().await?;
//! // Create a context with mobile viewport and geolocation
//! let context = browser.new_context_builder()
//! .viewport(390, 844) // iPhone 14 size
//! .device_scale_factor(3.0)
//! .is_mobile(true)
//! .has_touch(true)
//! .geolocation(37.7749, -122.4194) // San Francisco
//! .permissions(vec![Permission::Geolocation])
//! .build()
//! .await?;
//!
//! let page = context.new_page().await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Screenshots and PDF
//!
//! Capture screenshots and generate PDFs:
//!
//! ```no_run
//! use viewpoint_core::Browser;
//! use viewpoint_core::page::PaperFormat;
//!
//! # async fn example() -> Result<(), viewpoint_core::CoreError> {
//! # let browser = Browser::launch().headless(true).launch().await?;
//! # let context = browser.new_context().await?;
//! # let page = context.new_page().await?;
//! // Screenshot the viewport
//! page.screenshot()
//! .path("screenshot.png")
//! .capture()
//! .await?;
//!
//! // Full page screenshot
//! page.screenshot()
//! .full_page(true)
//! .path("full-page.png")
//! .capture()
//! .await?;
//!
//! // Generate PDF (headless only)
//! page.pdf()
//! .format(PaperFormat::A4)
//! .path("document.pdf")
//! .generate()
//! .await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Event Handling
//!
//! Handle browser events like dialogs and downloads:
//!
//! ```ignore
//! use viewpoint_core::Browser;
//!
//! # async fn example() -> Result<(), viewpoint_core::CoreError> {
//! # let browser = Browser::launch().headless(true).launch().await?;
//! # let context = browser.new_context().await?;
//! # let page = context.new_page().await?;
//! // Handle dialogs (alerts, confirms, prompts)
//! page.on_dialog(|dialog| async move {
//! println!("Dialog message: {}", dialog.message());
//! dialog.accept(None).await
//! }).await;
//!
//! // Handle downloads
//! page.on_download(|download| async move {
//! download.save_as("downloads/file.zip").await
//! }).await;
//!
//! // Handle console messages
//! page.on_console(|msg| async move {
//! println!("[{}] {}", msg.message_type(), msg.text());
//! Ok(())
//! }).await;
//! # Ok(())
//! # }
//! ```
//!
//! ## Module Organization
//!
//! - [`browser`] - Browser launching and connection management
//! - [`context`] - Browser context (similar to incognito window) management
//! - [`page`] - Page navigation, content, and interaction
//! - [`network`] - Network interception, routing, and HAR recording
//! - [`wait`] - Wait system and load states
//! - [`devices`] - Predefined device descriptors
//! - [`error`] - Error types
//! - [`api`] - API request context for HTTP requests
pub use ;
pub use ;
pub use CoreError;
pub use ;
pub use ;
pub use DocumentLoadState;