pub struct CookieReader;Implementations§
Source§impl CookieReader
impl CookieReader
§Errors
Returns an error if the cookies file is not found, cannot be read, or decryption fails.
Examples found in repository?
examples/test_codex.rs (line 13)
4async fn main() {
5 let detector = BrowserDetector::new();
6 let browsers = detector.detect_browsers();
7
8 for browser in &browsers {
9 if !browser.is_chromium_based() {
10 continue;
11 }
12 for prof in detector.list_profiles(*browser) {
13 if let Ok(cookies) = CookieReader::read_cookies(&prof, "chatgpt.com") {
14 let has_session = cookies
15 .iter()
16 .any(|c| c.name.starts_with("__Secure-next-auth.session-token"));
17
18 if !has_session {
19 continue;
20 }
21
22 println!(
23 "Using {} - {} ({} cookies)",
24 browser.name(),
25 prof.name,
26 cookies.len(),
27 );
28
29 match seher::codex::CodexClient::fetch_usage(&cookies).await {
30 Ok(usage) => {
31 println!("\nSuccess! Codex usage:");
32 println!(" plan_type: {}", usage.plan_type);
33 println!(" rate_limit limited: {}", usage.rate_limit.is_limited());
34 println!(
35 " rate_limit reset_time: {:?}",
36 usage.rate_limit.next_reset_time()
37 );
38 println!(
39 " code_review limited: {}",
40 usage.code_review_rate_limit.is_limited()
41 );
42 return;
43 }
44 Err(e) => {
45 println!("\nFailed to fetch Codex usage: {e}");
46 }
47 }
48 }
49 }
50 }
51
52 println!("No chatgpt.com session with __Secure-next-auth.session-token found");
53}More examples
examples/test_copilot.rs (line 13)
4async fn main() {
5 let detector = BrowserDetector::new();
6 let browsers = detector.detect_browsers();
7
8 for browser in &browsers {
9 if !browser.is_chromium_based() {
10 continue;
11 }
12 for prof in detector.list_profiles(*browser) {
13 if let Ok(cookies) = CookieReader::read_cookies(&prof, "github.com") {
14 let has_user_session = cookies
15 .iter()
16 .any(|c| c.name == "user_session" || c.name == "__Host-user_session_same_site");
17
18 if !has_user_session {
19 continue;
20 }
21
22 let dotcom_user = cookies
23 .iter()
24 .find(|c| c.name == "dotcom_user")
25 .map_or("unknown", |c| c.value.as_str());
26 println!(
27 "Using {} - {} ({} cookies, user={})",
28 browser.name(),
29 prof.name,
30 cookies.len(),
31 dotcom_user
32 );
33
34 match seher::copilot::CopilotClient::fetch_quota(&cookies).await {
35 Ok(quota) => {
36 println!("\nSuccess! Copilot quota:");
37 println!(" chat_utilization: {:.1}%", quota.chat_utilization);
38 println!(" premium_utilization: {:.1}%", quota.premium_utilization);
39 println!(" reset_time: {:?}", quota.reset_time);
40 println!(" is_limited: {}", quota.is_limited());
41 return;
42 }
43 Err(e) => {
44 println!("\nFailed to fetch Copilot quota: {e}");
45 }
46 }
47 }
48 }
49 }
50
51 println!("No github.com session with user_session cookie found");
52}Auto Trait Implementations§
impl Freeze for CookieReader
impl RefUnwindSafe for CookieReader
impl Send for CookieReader
impl Sync for CookieReader
impl Unpin for CookieReader
impl UnsafeUnpin for CookieReader
impl UnwindSafe for CookieReader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more