Skip to main content

tauri_plugin_webdriver/
lib.rs

1use tauri::{
2    plugin::{Builder, TauriPlugin},
3    Manager, Runtime,
4};
5
6#[cfg(desktop)]
7mod desktop;
8#[cfg(mobile)]
9mod mobile;
10
11mod error;
12mod platform;
13mod server;
14mod webdriver;
15
16pub use error::{Error, Result};
17
18/// Default port for the `WebDriver` HTTP server
19const DEFAULT_PORT: u16 = 4445;
20
21/// Initializes the plugin.
22#[must_use]
23pub fn init<R: Runtime>() -> TauriPlugin<R> {
24    Builder::new("webdriver")
25        .setup(|app, api| {
26            #[cfg(mobile)]
27            let webdriver = mobile::init(app, api)?;
28            #[cfg(desktop)]
29            let webdriver = desktop::init(app, api);
30            app.manage(webdriver);
31
32            // Start the WebDriver HTTP server
33            let app_handle = app.app_handle().clone();
34            server::start(app_handle, DEFAULT_PORT);
35            tracing::info!("WebDriver plugin initialized on port {DEFAULT_PORT}");
36
37            Ok(())
38        })
39        .build()
40}