mirror of
https://github.com/0xMassi/webclaw.git
synced 2026-04-25 00:06:21 +02:00
feat: add --cookie-file support for JSON cookie files
- --cookie-file reads Chrome extension format ([{name, value, domain, ...}])
- Works with EditThisCookie, Cookie-Editor, and similar browser extensions
- Merges with --cookie when both provided
- MCP scrape tool now accepts cookies parameter
- Closes #7
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
44f23332cc
commit
da1d76c97a
4 changed files with 71 additions and 10 deletions
|
|
@ -139,19 +139,33 @@ impl WebclawMcp {
|
|||
let exclude = params.exclude_selectors.unwrap_or_default();
|
||||
let main_only = params.only_main_content.unwrap_or(false);
|
||||
|
||||
// Use a custom client if a non-default browser is requested
|
||||
// Build cookie header from params
|
||||
let cookie_header = params
|
||||
.cookies
|
||||
.as_ref()
|
||||
.filter(|c| !c.is_empty())
|
||||
.map(|c| c.join("; "));
|
||||
|
||||
// Use a custom client if non-default browser or cookies are provided
|
||||
let is_default_browser = matches!(browser, webclaw_fetch::BrowserProfile::Chrome);
|
||||
let needs_custom = !is_default_browser || cookie_header.is_some();
|
||||
let custom_client;
|
||||
let client: &webclaw_fetch::FetchClient = if is_default_browser {
|
||||
&self.fetch_client
|
||||
} else {
|
||||
let client: &webclaw_fetch::FetchClient = if needs_custom {
|
||||
let mut headers = std::collections::HashMap::new();
|
||||
headers.insert("Accept-Language".to_string(), "en-US,en;q=0.9".to_string());
|
||||
if let Some(ref cookies) = cookie_header {
|
||||
headers.insert("Cookie".to_string(), cookies.clone());
|
||||
}
|
||||
let config = webclaw_fetch::FetchConfig {
|
||||
browser,
|
||||
headers,
|
||||
..Default::default()
|
||||
};
|
||||
custom_client = webclaw_fetch::FetchClient::new(config)
|
||||
.map_err(|e| format!("Failed to build client: {e}"))?;
|
||||
&custom_client
|
||||
} else {
|
||||
&self.fetch_client
|
||||
};
|
||||
|
||||
let formats = [format];
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ pub struct ScrapeParams {
|
|||
pub only_main_content: Option<bool>,
|
||||
/// Browser profile: "chrome" (default), "firefox", or "random"
|
||||
pub browser: Option<String>,
|
||||
/// Cookies to send with the request (e.g. ["name=value", "session=abc123"])
|
||||
pub cookies: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, JsonSchema)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue