1use crowser::{error::CrowserError, RemoteConfig, Window};
2
3fn main() -> Result<(), CrowserError> {
4 let mut profile_dir = std::env::current_dir()?;
5 profile_dir.push("example_profiles");
6
7 let config = RemoteConfig {
8 url: "https://example.com".to_string(),
9 };
10
11 let mut window = Window::new(config, None, profile_dir)?;
12 let ipc = window.ipc();
13
14 window.clear_profile().unwrap_or_default();
15
16 std::thread::spawn(move || {
17 ipc.block_until_initialized().unwrap_or_default();
18
19 ipc
20 .register_command("hello", |_| {
21 println!("Got hello command");
22 Ok(serde_json::json!("Hello from Crowser!"))
23 })
24 .unwrap_or_default();
25
26 std::thread::sleep(std::time::Duration::from_secs(1));
27
28 let result = ipc
30 .eval("window.__CROWSER.ipc.invoke('hello')")
31 .unwrap_or_default();
32 println!("Result: {:?}", result);
33 });
34
35 window.create()?;
36
37 Ok(())
38}