# browser-info
[](https://github.com/frkavka/browser-info/actions/workflows/rust.yml)
[](https://crates.io/crates/browser-info)
[](https://docs.rs/browser-info)
[](https://opensource.org/licenses/MIT)
## ๐ Used by
- **[Atode-GUI(mine)](https://github.com/frkavka/Atode-GUI)** - Read-later article management tool with quick save functionality
*If you use browser-info in your project, let me know and I'll add you to the list!*
๐ Cross-platform library for retrieving active browser URL and detailed information.
Fast, reliable, and easy-to-use browser information extraction with multiple strategies.
## โจ Features
- โก **Ultra Fast**: PowerShell-based extraction (sub-millisecond performance)
- ๐ง **DevTools Support**: Chrome DevTools Protocol for advanced scenarios (Windows only)
- ๐ **Multi-Browser**: Chrome, Firefox, Edge, Safari, Brave, Opera, Vivaldi
- ๐๏ธ **Multiple Strategies**: Choose between speed, compatibility, or detailed info
- ๐ **Auto Fallback**: Intelligent method selection with graceful fallbacks
- ๐ฅ๏ธ **Cross-Platform**: Windows (full support), macOS (partial), Linux (planned)
- ๐ **Security-First**: No vulnerable dependencies, regular security audits
## ๐ Quick Start
### Basic Usage
```rust
use browser_info::get_active_browser_info;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Check if a browser is currently active
if !browser_info::is_browser_active() {
println!("No browser is currently active");
return Ok(());
}
// Get comprehensive browser information
let info = get_active_browser_info()?;
println!("๐ Title: {}", info.title);
println!("๐ URL: {}", info.url);
println!("๐ Browser: {:?}", info.browser_type);
println!("๐ Position: ({}, {})", info.window_position.x, info.window_position.y);
println!("๐ Incognito: {}", info.is_incognito);
Ok(())
}
```
### Async API (with DevTools support)
```rust
use browser_info::{get_browser_info, ExtractionMethod};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Auto-detection with fallback (PowerShell โ DevTools)
let info = get_browser_info().await?;
println!("URL: {}", info.url);
Ok(())
}
```
### Method Selection
```rust
use browser_info::{get_browser_info_safe, ExtractionMethod, get_browser_info_with_method};
// Fast & Compatible (PowerShell - Recommended)
let info = get_browser_info_safe()?;
// Just get the URL (lightweight)
let url = browser_info::get_active_browser_url()?;
// Explicit Method Selection
let info = get_browser_info_with_method(ExtractionMethod::PowerShell).await?;
// DevTools method (Windows only, requires debug mode)
#[cfg(all(feature = "devtools", target_os = "windows"))]
let info = browser_info::get_browser_info_detailed().await?;
```
## ๐ฆ Installation
Add to your `Cargo.toml`:
```toml
[dependencies]
browser-info = "0.2"
# Optional: for async API and DevTools support
tokio = { version = "1.0", features = ["full"] }
reqwest = { version = "0.11", features = ["json"] }
```
### Features
- `default = ["devtools"]`: Includes DevTools support (Windows only)
- `devtools`: Chrome DevTools Protocol support (requires `reqwest` and `tokio`)
## ๐๏ธ Extraction Methods
| **Auto** | โก Fast | None | Windows, macOS | General use (recommended) |
| **PowerShell** | โก Ultra Fast | None | Windows | Production, reliability |
| **DevTools** | ๐ง Moderate | Chrome debug mode | Windows only | Advanced info, no UI interference |
| **AppleScript** | ๐ Fast | None | macOS only | Native macOS support |
### Platform Support
| **Windows** | โ
Full | PowerShell, DevTools, Auto |
| **macOS** | ๐ง Partial | AppleScript, Auto |
| **Linux** | โณ Planned | Coming soon |
### Chrome DevTools Setup (Optional)
For DevTools method on Windows, start Chrome with debug mode:
```bash
chrome.exe --remote-debugging-port=9222 --user-data-dir=temp
```
## ๐ Performance
Based on our benchmarks:
- **PowerShell**: ~0.4ms (sub-millisecond)
- **AppleScript**: ~50ms (native macOS)
- **DevTools**: ~300ms (network overhead)
- **Auto**: Uses fastest available method per platform
## ๐ง Development
### Building
```bash
# Build with all features
cargo build --all-features
# Build without DevTools (faster compilation)
cargo build --no-default-features
# Platform-specific builds
cargo build --target x86_64-pc-windows-msvc
cargo build --target x86_64-apple-darwin
```
### Testing
```bash
# Run all tests
cargo test --all-features
# Run platform-specific tests
cargo test --features devtools # Windows only
```
## ๐ Examples
Check out `/examples` for more usage patterns:
```bash
cargo run --example basic_usage
```
## ๐งช Benchmarking
Run performance tests:
```bash
cargo bench
```
View detailed HTML reports in `target/criterion/`.
## ๐ก๏ธ Security
This library prioritizes security:
- โ
**No vulnerable dependencies** - Regular security audits with `cargo audit`
- โ
**Safe Rust** - No unsafe code blocks
- โ
**Input validation** - All external data is validated
- โ
**CI/CD security** - Automated security scanning in GitHub Actions
## ๐ Troubleshooting
### Common Issues
**Windows**: "PowerShell execution policy"
```bash
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
```
**DevTools**: "Connection refused"
- Ensure Chrome is running with `--remote-debugging-port=9222`
- Check if port 9222 is not blocked by firewall
### Debug Mode
Enable debug logging:
```rust
env_logger::init();
let info = get_active_browser_info()?;
```
## ๐ค Contributing
Contributions welcome! Please see our [contributing guidelines](CONTRIBUTING.md).
### Development Setup
1. Clone the repository
2. Install Rust (1.87+ required)
3. Run tests: `cargo test --all-features`
4. Submit a pull request
### Roadmap
- [ ] Linux support (X11 and Wayland)
- [ ] Firefox DevTools Protocol support
- [ ] Browser extension API
- [ ] WebDriver integration
## ๐ License
Licensed under MIT License. See [LICENSE](LICENSE) for details.
---
<div align="center">
<sub>Built with โค๏ธ by <a href="https://github.com/frkavka">Katy</a></sub>
</div>