Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,39 @@ google-patent-cli config
# Set custom browser path
google-patent-cli config --set-browser "/path/to/chrome"
```


### Configuration File

The configuration file is located at:
- **Linux/macOS**: `~/.config/google-patent-cli/config.toml`
- **Windows**: `%APPDATA%\google-patent-cli\config.toml`

You can manually edit the TOML file to configure additional Chrome arguments:

```toml
# Path to Chrome/Chromium executable
browser_path = "/usr/bin/google-chrome"

# Additional Chrome arguments (useful for Docker/CI environments)
chrome_args = [
"--no-sandbox",
"--disable-setuid-sandbox"
]
```

### Docker/DevContainer Environment

When running in Docker containers or devcontainers, Chrome requires additional flags to work properly. You can configure these flags via `chrome_args` in your config file:

```toml
chrome_args = [
"--no-sandbox",
"--disable-setuid-sandbox",
"--disable-gpu"
]
```

Alternatively, set the `CI=true` environment variable to automatically add these flags.

## License
MIT
24 changes: 18 additions & 6 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,15 @@ pub async fn run_app(cli: Cli) -> Result<()> {
}

let config = Config::load()?;
let searcher =
PatentSearcher::new(config.browser_path, !args.head, args.debug, args.verbose)
.await?;
let chrome_args = config.chrome_args.clone();
let searcher = PatentSearcher::new(
config.browser_path,
!args.head,
args.debug,
args.verbose,
chrome_args,
)
.await?;

let options = SearchOptions {
query: args.query,
Expand All @@ -162,9 +168,15 @@ pub async fn run_app(cli: Cli) -> Result<()> {
}
Commands::Fetch { args } => {
let config = Config::load()?;
let searcher =
PatentSearcher::new(config.browser_path, !args.head, args.debug, args.verbose)
.await?;
let chrome_args = config.chrome_args.clone();
let searcher = PatentSearcher::new(
config.browser_path,
!args.head,
args.debug,
args.verbose,
chrome_args,
)
.await?;

if args.raw {
let html = searcher.get_raw_html(&args.patent_id, args.language.as_deref()).await?;
Expand Down
17 changes: 15 additions & 2 deletions src/core/cdp/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,17 @@ pub struct BrowserManager {
browser_path: Option<PathBuf>,
headless: bool,
debug: bool,
chrome_args: Vec<String>,
state: Arc<Mutex<BrowserState>>,
}

impl BrowserManager {
pub fn new(browser_path: Option<PathBuf>, headless: bool, debug: bool) -> Self {
pub fn new(
browser_path: Option<PathBuf>,
headless: bool,
debug: bool,
chrome_args: Vec<String>,
) -> Self {
let state = Arc::new(Mutex::new(BrowserState { browser: None, last_used: Instant::now() }));

// Spawn the inactivity monitor task
Expand All @@ -354,7 +360,7 @@ impl BrowserManager {
}
});

Self { browser_path, headless, debug, state }
Self { browser_path, headless, debug, chrome_args, state }
}

pub async fn get_browser(&self) -> Result<Arc<CdpBrowser>> {
Expand All @@ -369,6 +375,13 @@ impl BrowserManager {

if std::env::var("CI").is_ok() {
args.push("--disable-gpu");
args.push("--no-sandbox");
args.push("--disable-setuid-sandbox");
}

// Add custom Chrome args from config
for arg in &self.chrome_args {
args.push(arg.as_str());
}

let browser_path = self.browser_path.clone();
Expand Down
2 changes: 2 additions & 0 deletions src/core/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use std::path::{Path, PathBuf};
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
pub struct Config {
pub browser_path: Option<PathBuf>,
#[serde(default)]
pub chrome_args: Vec<String>,
}

impl Config {
Expand Down
3 changes: 2 additions & 1 deletion src/core/patent_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ impl PatentSearcher {
headless: bool,
debug: bool,
verbose: bool,
chrome_args: Vec<String>,
) -> Result<Self> {
let browser_manager = BrowserManager::new(browser_path, headless, debug);
let browser_manager = BrowserManager::new(browser_path, headless, debug, chrome_args);

Ok(Self { browser_manager, verbose })
}
Expand Down
3 changes: 2 additions & 1 deletion src/mcp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ impl ServerHandler for PatentHandler {
/// Run the MCP server over stdio
pub async fn run() -> anyhow::Result<()> {
let config = Config::load()?;
let searcher = PatentSearcher::new(config.browser_path, true, false, false)
let chrome_args = config.chrome_args.clone();
let searcher = PatentSearcher::new(config.browser_path, true, false, false, chrome_args)
.await
.map_err(|e| anyhow::anyhow!("Failed to create PatentSearcher: {}", e))?;
let handler = PatentHandler::new(Arc::new(searcher));
Expand Down