pub mod abort;
pub mod artifacts;
pub mod bdd;
pub mod blob;
pub mod browser;
pub mod browser_type;
pub mod console_message;
pub mod context;
pub mod convert;
pub mod dialog;
pub mod disposable;
pub mod download;
pub mod element_handle;
pub mod expect;
pub mod fetch;
pub mod file_chooser;
pub mod form_data;
pub mod frame;
pub mod frame_locator;
pub mod http_client;
pub mod js_handle;
pub mod keyboard;
pub mod locator;
pub mod mouse;
pub mod network;
pub mod page;
pub mod plugins;
pub mod process;
pub mod streams;
pub mod video;
pub mod web_error;
pub mod webapi;
pub use artifacts::ArtifactsJs;
pub use bdd::{
CollectedAllow, CollectedRegistry, CollectedTool, HookArg, JsArg, ScenarioWorld, ScriptAttachment, StepOutcome,
collect_registry, drain_attachments, install_bdd, invoke_hook, invoke_step, reset_world, set_scenario_world,
tools_len, tools_snapshot,
};
pub use browser::BrowserJs;
pub use browser_type::{BrowserTypeJs, install_browser_type};
pub use console_message::ConsoleMessageJs;
pub use context::BrowserContextJs;
pub use dialog::DialogJs;
pub use disposable::DisposableJs;
pub use download::DownloadJs;
pub use element_handle::ElementHandleJs;
pub use file_chooser::FileChooserJs;
pub use frame::FrameJs;
pub use frame_locator::FrameLocatorJs;
pub use http_client::{HttpClientJs, HttpResponseJs};
pub use js_handle::JSHandleJs;
pub use keyboard::KeyboardJs;
pub use locator::LocatorJs;
pub use mouse::MouseJs;
pub use network::{RequestJs, ResponseJs, RouteJs, WebSocketJs};
pub use page::PageJs;
pub use plugins::{PluginBinding, PluginCommandsJs, install_plugins};
pub use video::VideoJs;
pub use web_error::WebErrorJs;
use rquickjs::{AsyncContext, Ctx, class::Class};
use std::sync::Arc;
pub fn define_classes<'js>(ctx: &Ctx<'js>) -> rquickjs::Result<()> {
let g = ctx.globals();
Class::<PageJs>::define(&g)?;
Class::<FrameJs>::define(&g)?;
Class::<LocatorJs>::define(&g)?;
Class::<BrowserContextJs>::define(&g)?;
Class::<BrowserJs>::define(&g)?;
Class::<HttpClientJs>::define(&g)?;
Class::<HttpResponseJs>::define(&g)?;
Class::<KeyboardJs>::define(&g)?;
Class::<MouseJs>::define(&g)?;
Class::<ArtifactsJs>::define(&g)?;
Class::<JSHandleJs>::define(&g)?;
Class::<ElementHandleJs>::define(&g)?;
Class::<RouteJs>::define(&g)?;
Class::<WebSocketJs>::define(&g)?;
Class::<DialogJs>::define(&g)?;
Class::<FileChooserJs>::define(&g)?;
Class::<DownloadJs>::define(&g)?;
Class::<DisposableJs>::define(&g)?;
Class::<ConsoleMessageJs>::define(&g)?;
Class::<WebErrorJs>::define(&g)?;
Class::<VideoJs>::define(&g)?;
Class::<BrowserTypeJs>::define(&g)?;
Class::<FrameLocatorJs>::define(&g)?;
Class::<crate::bindings::page::TouchscreenJs>::define(&g)?;
Class::<crate::bindings::fetch::HeadersJs>::define(&g)?;
Class::<crate::bindings::fetch::FetchResponseJs>::define(&g)?;
Class::<crate::bindings::fetch::FetchRequestJs>::define(&g)?;
Class::<crate::bindings::abort::AbortControllerJs<'js>>::define(&g)?;
Class::<crate::bindings::abort::AbortSignalJs<'js>>::define(&g)?;
Class::<crate::bindings::streams::ReadableStreamJs>::define(&g)?;
Class::<crate::bindings::streams::ReadableStreamDefaultReaderJs>::define(&g)?;
Class::<crate::bindings::streams::ReadableStreamDefaultControllerJs>::define(&g)?;
Class::<crate::bindings::blob::BlobJs>::define(&g)?;
Class::<crate::bindings::form_data::FormDataJs>::define(&g)?;
Ok(())
}
pub fn install_page(ctx: &Ctx<'_>, page: Arc<ferridriver::Page>, async_ctx: AsyncContext) -> rquickjs::Result<()> {
install_page_on(ctx, &ctx.globals(), page, async_ctx)
}
pub fn install_page_on<'js>(
ctx: &Ctx<'js>,
target: &rquickjs::Object<'js>,
page: Arc<ferridriver::Page>,
async_ctx: AsyncContext,
) -> rquickjs::Result<()> {
let js_page = Class::instance(ctx.clone(), PageJs::new_with_async_ctx(page, async_ctx))?;
target.set("page", js_page)?;
page::ensure_page_callbacks(ctx);
Ok(())
}
pub fn install_browser_context(ctx: &Ctx<'_>, bcx: Arc<ferridriver::context::ContextRef>) -> rquickjs::Result<()> {
install_browser_context_on(ctx, &ctx.globals(), bcx)
}
pub fn install_browser_context_on<'js>(
ctx: &Ctx<'js>,
target: &rquickjs::Object<'js>,
bcx: Arc<ferridriver::context::ContextRef>,
) -> rquickjs::Result<()> {
let js_bcx = Class::instance(ctx.clone(), BrowserContextJs::new(bcx))?;
target.set("context", js_bcx)?;
Ok(())
}
pub fn install_browser(ctx: &Ctx<'_>, browser: Arc<ferridriver::Browser>) -> rquickjs::Result<()> {
install_browser_on(ctx, &ctx.globals(), browser)
}
pub fn install_browser_on<'js>(
ctx: &Ctx<'js>,
target: &rquickjs::Object<'js>,
browser: Arc<ferridriver::Browser>,
) -> rquickjs::Result<()> {
let js_browser = Class::instance(ctx.clone(), BrowserJs::new(browser))?;
target.set("browser", js_browser)?;
Ok(())
}
pub fn install_request(ctx: &Ctx<'_>, req: Arc<ferridriver::http_client::HttpClient>) -> rquickjs::Result<()> {
install_request_on(ctx, &ctx.globals(), req)
}
pub fn install_request_on<'js>(
ctx: &Ctx<'js>,
target: &rquickjs::Object<'js>,
req: Arc<ferridriver::http_client::HttpClient>,
) -> rquickjs::Result<()> {
let js_req = Class::instance(ctx.clone(), HttpClientJs::new(req))?;
target.set("request", js_req)?;
Ok(())
}
pub fn install_artifacts(ctx: &Ctx<'_>, sandbox: Arc<crate::fs::PathSandbox>) -> rquickjs::Result<()> {
let js_art = Class::instance(ctx.clone(), ArtifactsJs::new(sandbox))?;
ctx.globals().set("artifacts", js_art)?;
Ok(())
}