| Crates.io | websnap |
| lib.rs | websnap |
| version | 0.1.0 |
| created_at | 2025-04-22 06:51:29.98898+00 |
| updated_at | 2025-04-22 06:51:29.98898+00 |
| description | WebSnap is a command-line tool for capturing screenshots of websites. |
| homepage | https://github.com/canmi21/websnap |
| repository | https://github.com/canmi21/websnap |
| max_upload_size | |
| id | 1643685 |
| size | 32,558 |
WebSnap is a command-line tool for capturing screenshots of websites. It provides two implementations: a Rust-based version that uses Google Chrome in headless mode to capture screenshots, and a WebAssembly (WASM) version that serves as a placeholder for browser-based screenshot functionality. The tool allows customization of screenshot dimensions, user-agent strings, output formats, and more.
cargo, rustc).clap, chrono, serde, md5.wasm-pack for building WebAssembly.git clone https://github.com/canmi21/websnap.git
cd websnap
cargo build --release
target/release/websnap.wasm-pack:
cargo install wasm-pack
wasm-pack build --target web
pkg directory with the WASM module and JavaScript glue code.Run the tool with the following command:
websnap --target <URL> [OPTIONS]
-o, --output <FILE>: Output file or path for the screenshot.-d, --debug: Enable debug output.-h, --height <PIXELS>: Screenshot height (default: 1080).-w, --width <PIXELS>: Screenshot width (default: 1920).-s, --sleep <SECONDS>: Sleep time before capturing (default: 0).-u, --ua <STRING>: Custom User-Agent string.-t, --target <URL>: Target URL to capture (e.g., https://example.com).-f, --format <FORMAT>: Output format (png, webp, jpg).--help: Print help information.Capture a screenshot of https://example.com with a custom size and output format:
websnap -t https://example.com -o screenshot.png -w 1280 -h 720 -f png -d
The WASM version is a placeholder and logs parameters to the console. To integrate it into a web project:
index.html):
<!DOCTYPE html>
<html>
<head>
<title>WebSnap WASM</title>
</head>
<body>
<script type="module">
import init, { capture_screenshot } from './pkg/websnap.js';
async function run() {
await init();
capture_screenshot(
"https://example.com",
"screenshot.png",
1920,
1080,
"Mozilla/5.0",
2,
true
);
}
run();
</script>
</body>
</html>
pkg directory to your web project.npx serve).Note: The WASM version requires a JavaScript-based screenshot implementation (e.g., using Puppeteer or canvas) to be fully functional.
cargo build --release
cargo test
cargo package
wasm-pack build --target web
npx serve
wasm-pack pack
To publish the WASM module to npm:
pkg/package.json with your project details (e.g., name, version).cd pkg
npm publish
npm install websnap
websnap/
├── src/
│ ├── main.rs # Rust CLI implementation
│ └── lib.rs # WASM implementation
├── Cargo.toml # Rust dependencies and metadata
├── README.md # This file
└── pkg/ # WASM output (after wasm-pack build)
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
MIT License. See LICENSE for details.