-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
760e90a
commit 1c7b876
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use futures::StreamExt; | ||
|
||
use chromiumoxide::browser::Browser; | ||
use chromiumoxide::browser::BrowserConfig; | ||
use chromiumoxide::cdp::browser_protocol::network::CookieParam; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
tracing_subscriber::fmt::init(); | ||
|
||
let (mut browser, mut handler) = | ||
Browser::launch(BrowserConfig::builder().with_head().build()?).await?; | ||
let _ = tokio::spawn(async move { while let Some(_) = handler.next().await {} }); | ||
|
||
let _ = browser.new_page("https://setcookie.net/").await?; | ||
let example_cookie = CookieParam::builder() | ||
.domain(".setcookie.net") | ||
.name("set_from_chromiumoxide") | ||
.value("Test Value") | ||
.path("/") | ||
.build()?; | ||
|
||
println!("\x1b[32mType 'c' to clear all cookies, 's' to set a cookie, 'q' to quit the browser\x1b[0m"); | ||
loop { | ||
// Read Cookies | ||
println!("All Browser cookies: {:?}", browser.get_cookies().await?); | ||
|
||
let mut input = String::new(); | ||
std::io::stdin().read_line(&mut input)?; | ||
|
||
if input.trim() == "c" { | ||
// Clear Cookies | ||
browser.clear_cookies().await?; | ||
} | ||
if input.trim() == "s" { | ||
// Set Cookies | ||
browser.set_cookies(vec![example_cookie.clone()]).await?; | ||
} | ||
if input.trim() == "q" { | ||
break; | ||
} | ||
} | ||
|
||
browser.close().await?; | ||
browser.wait().await?; | ||
|
||
Ok(()) | ||
} |