Skip to main content

vs_engine_webkit/
lib.rs

1//! WebKit engine binding for vibesurfer.
2//!
3//! This crate hosts the [`Engine`] trait — the daemon's view of "a
4//! browser" — and the [`EngineRuntime`] that pins the implementation
5//! to a dedicated OS thread (the only thread that may call WebKit on
6//! either supported platform).
7//!
8//! # Backends
9//!
10//! - [`backend::webkit`] *(macOS)* — system WebKit framework via
11//!   `objc2` + `objc2-web-kit`, driven from the Cocoa main thread.
12//! - [`backend::wpe`] *(Linux)* — WebKitGTK 6 via `webkit6` + `glib`,
13//!   driven from a thread that owns a GLib main context.
14//! - [`backend::webview2`] *(Windows)* — WebView2 via `webview2-com` +
15//!   `windows-rs`, driven from a thread that owns a Win32 message pump.
16//!
17//! All backends implement [`Engine`]; [`EngineRuntime::spawn`] is
18//! generic over the constructor so the daemon can pick a backend at
19//! runtime without compile-time coupling.
20
21#![cfg_attr(
22    not(any(target_os = "macos", target_os = "windows")),
23    forbid(unsafe_code)
24)]
25// On macOS we have a small surface of FFI to AppKit/WebKit. The unsafe
26// code is constrained to `backend::webkit`; everywhere else stays
27#![cfg_attr(
28    target_os = "macos",
29    allow(
30        clippy::redundant_closure_for_method_calls,
31        clippy::needless_pass_by_value,
32        clippy::type_complexity,
33        clippy::manual_map,
34        clippy::uninlined_format_args,
35        clippy::map_unwrap_or
36    )
37)]
38// unsafe-free.
39#![cfg_attr(any(target_os = "macos", target_os = "windows"), allow(unsafe_code))]
40
41pub mod backend;
42pub mod engine;
43pub mod inspector;
44pub mod runtime;
45
46#[cfg(any(test, feature = "test-support"))]
47pub mod test_support;
48
49pub use engine::{
50    ActTarget, Action, AuthBlob, CaptureScope, Engine, EngineCapabilities, EngineError,
51    EngineResult, LayoutBox, PageHandle, Viewport, WaitCondition,
52};
53pub use inspector::{
54    ConsoleEntry, ConsoleLevel, Header, NetworkEntry, NetworkStatus, RequestDetail, RingBuffer,
55};
56pub use runtime::EngineRuntime;
57
58/// Returns the crate version (matches the workspace version).
59#[must_use]
60pub fn version() -> &'static str {
61    env!("CARGO_PKG_VERSION")
62}
63
64#[cfg(test)]
65mod tests {
66    use super::version;
67
68    #[test]
69    fn version_matches_cargo_pkg_version() {
70        assert_eq!(version(), env!("CARGO_PKG_VERSION"));
71    }
72}