Skip to content

Commit 41f15b0

Browse files
authored
Merge pull request #3 from greysquirr3l/docs/page-operations-status-code
docs(browser): document PageHandle::url() and status_code() in page-operations
2 parents 32e2eae + e5fd040 commit 41f15b0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

book/src/browser/page-operations.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ let title = page.title().await?;
4646
4747
// Current URL (may differ from navigated URL after redirects)
4848
let url = page.url().await?;
49+
50+
// HTTP status code of the last navigation, if available
51+
// (None if no navigation has committed yet, the URL is non-HTTP such as file://,
52+
// or network events were not captured)
53+
if let Some(status) = page.status_code()? {
54+
println!("HTTP {status}");
55+
}
4956
```
5057

5158
---
@@ -183,6 +190,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
183190
let count: u32 = page.eval("document.querySelectorAll('.product').length").await?;
184191
println!("{count} products found");
185192
193+
let url = page.url().await?;
194+
let status = page.status_code()?;
195+
match status {
196+
Some(code) => println!("{url} → HTTP {code}"),
197+
None => println!("{url} → HTTP status unknown"),
198+
}
199+
186200
let html = page.content().await?;
187201
// … pass html to an AI extraction node …
188202

0 commit comments

Comments
 (0)