ferridriver-script 0.4.0

Sandboxed QuickJS scripting engine for ferridriver. Runs JS scripts against Page/Browser/Context with bound args, per-call isolation, scoped fs, and structured errors.
Documentation
//! `VideoJs` — QuickJS binding for [`ferridriver::Video`].
//!
//! Mirrors Playwright's client-side `Video` class from
//! `/tmp/playwright/packages/playwright-core/src/client/video.ts` and
//! the public-type contract in
//! `/tmp/playwright/packages/playwright-core/types/types.d.ts:21621`:
//! sync construction, async `path()` / `saveAs()` / `delete()` that
//! block until the owning page closes and the encoder finalises.

use std::sync::Arc;

use crate::bindings::convert::FerriResultExt;
use ferridriver::Video as CoreVideo;
use rquickjs::JsLifetime;
use rquickjs::class::Trace;

#[derive(JsLifetime, Trace)]
#[rquickjs::class(rename = "Video")]
pub struct VideoJs {
  #[qjs(skip_trace)]
  inner: Arc<CoreVideo>,
}

impl VideoJs {
  #[must_use]
  pub fn new(inner: Arc<CoreVideo>) -> Self {
    Self { inner }
  }
}

#[rquickjs::methods]
impl VideoJs {
  /// Playwright: `video.path(): Promise<string>`.
  #[qjs(rename = "path")]
  pub async fn path(&self) -> rquickjs::Result<String> {
    let path = self.inner.path().await.into_js()?;
    Ok(path.to_string_lossy().into_owned())
  }

  /// Playwright: `video.saveAs(path: string): Promise<void>`.
  #[qjs(rename = "saveAs")]
  pub async fn save_as(&self, path: String) -> rquickjs::Result<()> {
    self.inner.save_as(path).await.into_js()
  }

  /// Playwright: `video.delete(): Promise<void>`.
  #[qjs(rename = "delete")]
  pub async fn delete(&self) -> rquickjs::Result<()> {
    self.inner.delete().await.into_js()
  }
}