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
//! playwright: High-level Rust bindings for Microsoft Playwright
//!
//! This crate provides the public API for browser automation using Playwright.
//!
//! # Quick tour
//!
//! ## Object model
//!
//! ```text
//! Playwright start here — Playwright::launch().await?
//! └── BrowserType .chromium() / .firefox() / .webkit()
//! └── Browser .launch().await? → owns the browser process
//! └── BrowserContext isolated cookies / storage
//! └── Page one tab
//! └── Locator selector with auto-wait
//! ```
//!
//! [`Locator`] is the workhorse. Build one with [`Page::locator`] or one
//! of the semantic helpers (`get_by_role`, `get_by_text`, `get_by_label`,
//! `get_by_placeholder`, `get_by_test_id`, `get_by_alt_text`,
//! `get_by_title`), then call action / assertion methods on it — they
//! wait for the element to be actionable automatically.
//!
//! ## API conventions
//!
//! - **`Result<T>` everywhere.** One error type, [`Error`].
//! - **Builders for option-heavy methods.** `goto`, `click`, `screenshot`,
//! `tracing.start`, etc. take an `Options` struct (`..Default::default()`).
//! - **Auto-wait by default.** Locator-based actions wait until the
//! element is actionable; [`expect`] assertions auto-retry until the
//! condition holds or times out. You almost never need a manual `sleep`.
//! - **Async/await on `tokio`.** Every method that does I/O is `async`.
//! - **Selectors validated at compile time.** Prefer the [`locator!`]
//! macro (re-exported when the default `macros` feature is on) over
//! raw `&str`: empty / malformed selectors fail at `cargo build`, not
//! at runtime.
//!
//! ## Debugging failures
//!
//! Fastest path to "what happened" is tracing:
//!
//! 1. Wrap the test body with [`BrowserContext::tracing`] —
//! `start({ snapshots, screenshots, sources })` → run → `stop({ path })`.
//! 2. Open the resulting `.trace.zip` with
//! `playwright show-trace path/to/trace.zip` — the trace viewer is
//! language-agnostic, the same UI JS / Python users see.
//! 3. To inspect a trace programmatically (CI bots, agent feedback
//! loops), pull in [`playwright-rs-trace`](https://docs.rs/playwright-rs-trace)
//! as a `[dev-dependencies]`.
//!
//! See [`examples/trace_on_failure.rs`](https://github.com/padamson/playwright-rust/blob/main/crates/playwright/examples/trace_on_failure.rs)
//! for the canonical Rust pattern (Rust has no async `Drop`, so cleanup
//! is explicit).
//!
//! ## Companion crates
//!
//! - [`playwright-rs-macros`](https://docs.rs/playwright-rs-macros) —
//! compile-time-validated [`locator!`] macro. Default-on via the
//! `macros` feature; surfaced here as `playwright_rs::locator!`.
//! - [`playwright-rs-trace`](https://docs.rs/playwright-rs-trace) —
//! pure-Rust parser for `.trace.zip` files. Standalone; add to
//! `[dev-dependencies]` for post-mortem analysis.
//!
//! ## For AI coding agents
//!
//! If you're using this crate with Claude Code or another coding agent,
//! see [`docs/agent/`](https://github.com/padamson/playwright-rust/tree/main/docs/agent)
//! for a copy-paste CLAUDE.md snippet and the
//! [`playwright-rs-usage` skill](https://github.com/padamson/playwright-rust/tree/main/.claude/skills/playwright-rs-usage)
//! you can drop into your project's `.claude/skills/`.
//!
//! # Examples
//!
//! ## Basic Navigation and Interaction
//!
//! ```ignore
//! use playwright_rs::{Playwright, SelectOption};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let playwright = Playwright::launch().await?;
//! let browser = playwright.chromium().launch().await?;
//! let page = browser.new_page().await?;
//!
//! // Navigate using data URL for self-contained test
//! let _ = page.goto(
//! "data:text/html,<html><body>\
//! <h1 id='title'>Welcome</h1>\
//! <button id='btn' onclick='this.textContent=\"Clicked\"'>Click me</button>\
//! </body></html>",
//! None
//! ).await;
//!
//! // Query elements with locators
//! let heading = page.locator("#title").await;
//! let text = heading.text_content().await?;
//! assert_eq!(text, Some("Welcome".to_string()));
//!
//! // Click button and verify result
//! let button = page.locator("#btn").await;
//! button.click(None).await?;
//! let button_text = button.text_content().await?;
//! assert_eq!(button_text, Some("Clicked".to_string()));
//!
//! browser.close().await?;
//! Ok(())
//! }
//! ```
//!
//! ## Form Interaction
//!
//! ```ignore
//! use playwright_rs::{Playwright, SelectOption};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let playwright = Playwright::launch().await?;
//! let browser = playwright.chromium().launch().await?;
//! let page = browser.new_page().await?;
//!
//! // Create form with data URL
//! let _ = page.goto(
//! "data:text/html,<html><body>\
//! <input type='text' id='name' />\
//! <input type='checkbox' id='agree' />\
//! <select id='country'>\
//! <option value='us'>USA</option>\
//! <option value='uk'>UK</option>\
//! <option value='ca'>Canada</option>\
//! </select>\
//! </body></html>",
//! None
//! ).await;
//!
//! // Fill text input
//! let name = page.locator("#name").await;
//! name.fill("John Doe", None).await?;
//! assert_eq!(name.input_value(None).await?, "John Doe");
//!
//! // Check checkbox
//! let checkbox = page.locator("#agree").await;
//! checkbox.set_checked(true, None).await?;
//! assert!(checkbox.is_checked().await?);
//!
//! // Select option
//! let select = page.locator("#country").await;
//! select.select_option("uk", None).await?;
//! assert_eq!(select.input_value(None).await?, "uk");
//!
//! browser.close().await?;
//! Ok(())
//! }
//! ```
//!
//! ## Element Screenshots
//!
//! ```ignore
//! use playwright_rs::Playwright;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let playwright = Playwright::launch().await?;
//! let browser = playwright.chromium().launch().await?;
//! let page = browser.new_page().await?;
//!
//! // Create element to screenshot
//! let _ = page.goto(
//! "data:text/html,<html><body>\
//! <div id='box' style='width:100px;height:100px;background:blue'></div>\
//! </body></html>",
//! None
//! ).await;
//!
//! // Take screenshot of specific element
//! let element = page.locator("#box").await;
//! let screenshot = element.screenshot(None).await?;
//! assert!(!screenshot.is_empty());
//!
//! browser.close().await?;
//! Ok(())
//! }
//! ```
//!
//! ## Assertions (expect API)
//!
//! ```ignore
//! use playwright_rs::{expect, Playwright};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let playwright = Playwright::launch().await?;
//! let browser = playwright.chromium().launch().await?;
//! let page = browser.new_page().await?;
//!
//! let _ = page.goto(
//! "data:text/html,<html><body>\
//! <button id='enabled'>Enabled</button>\
//! <button id='disabled' disabled>Disabled</button>\
//! <input type='checkbox' id='checked' checked />\
//! </body></html>",
//! None
//! ).await;
//!
//! // Assert button states with auto-retry
//! let enabled_btn = page.locator("#enabled").await;
//! expect(enabled_btn.clone()).to_be_enabled().await?;
//!
//! let disabled_btn = page.locator("#disabled").await;
//! expect(disabled_btn).to_be_disabled().await?;
//!
//! // Assert checkbox state
//! let checkbox = page.locator("#checked").await;
//! expect(checkbox).to_be_checked().await?;
//!
//! browser.close().await?;
//! Ok(())
//! }
//! ```
//!
//! ## Observability
//!
//! Every public async method on the user-facing types
//! (`Browser`, `BrowserContext`, `BrowserType`, `Page`, `Frame`, `Locator`,
//! `ElementHandle`, `Tracing`, `CDPSession`, `Debugger`, `Screencast`, plus
//! `Request`, `Response`, `Dialog`, `Download`, `Worker`, `FileChooser`)
//! is instrumented with the [`tracing`] crate. Wire up any
//! `tracing_subscriber` and you get spans for free, with cardinality-bounded
//! identifiers (`guid`, `selector`, `url`, `name`) and selected
//! completion-time fields (`status`, `bytes_len`, `count`, `version`).
//! Internal `tokio::spawn` sites propagate the caller's span via
//! `Instrument::in_current_span()` so user-registered handlers and event
//! fan-out tasks inherit the surrounding context.
//!
//! Levels: top-level user operations (`goto`, `click`, `fill`, `screenshot`,
//! `pdf`, `evaluate`, `tracing.start/stop`, `browser_type.launch`) are at
//! `info`; everything else is at `debug`. Sensitive payloads — input
//! values, eval expressions, request/response bodies — are deliberately
//! excluded from span fields.
//!
//! ```ignore
//! use tracing_subscriber::EnvFilter;
//!
//! tracing_subscriber::fmt()
//! .with_env_filter(EnvFilter::new("playwright_rs=info"))
//! .init();
//! ```
// Internal modules (exposed for integration tests)
/// Playwright server version bundled with this crate.
///
/// This version determines which browser builds are compatible.
/// When installing browsers, use this version to ensure compatibility:
///
/// ```bash
/// npx playwright@1.60.0 install
/// ```
///
/// See: <https://playwright.dev/docs/browsers>
pub const PLAYWRIGHT_VERSION: &str = env!;
/// Default timeout in milliseconds for Playwright operations.
///
/// This matches Playwright's standard default across all language implementations (Python, Java, .NET, JS).
/// Required in Playwright 1.56.1+ when timeout parameter is not explicitly provided.
///
/// See: <https://playwright.dev/docs/test-timeouts>
pub const DEFAULT_TIMEOUT_MS: f64 = 30000.0;
// Re-export error types
pub use ;
// Re-export assertions API
pub use ;
// Screenshot-diff types are gated on the optional feature.
pub use ;
// Re-export Playwright main entry point and browser API
pub use ;
// Re-export input device types
pub use ;
// Re-export Request and related types
pub use ;
// Re-export Locator and element APIs
pub use ;
// Re-export navigation and page options
pub use ;
// Re-export action options
pub use ;
// Re-export Position (needed for DragToOptions and other options)
pub use Position;
// Re-export form and input types
pub use ;
// Re-export screenshot types
pub use ;
// Re-export screencast types
pub use ;
// Re-export new page method types
pub use ;
// Re-export browser context options and storage state types
pub use ;
// Re-export EventWaiter for use with expect_page() / expect_close()
pub use EventWaiter;
// Re-export EventValue for use with expect_event()
pub use EventValue;
// Re-export ConsoleMessage types
pub use ;
// Re-export device descriptor types
pub use ;
// Re-export WebError
pub use WebError;
// Re-export WebSocketRoute
pub use ;
// Re-export FileChooser
pub use FileChooser;
// Re-export Accessibility and Coverage types
pub use ;
// Re-export Clock types
pub use ;
// Re-export Video
pub use Video;
// Re-export routing types
pub use ;
// Re-export APIRequest public API
pub use ;
// Re-export launch and connection options
pub use ;
// Re-export browser installation helpers
pub use ;
// Re-export the `locator!` compile-time-validated selector macro from
// the companion `playwright-rs-macros` crate. Gated on the `macros`
// feature (default-on) so users without the proc-macro toolchain
// available can opt out.
pub use locator;