web-api-cat 0.7.14

Bindings between boa-cat (JS engine) and the DOM (html-cat tree) plus fetch (net-cat). v0.7.14 adds `getElementsByTagName(name)` (with `'*'` universal and empty-input-yields-empty per spec) and `getElementsByClassName(classNames)` (whitespace-separated; ALL classes must match) on both `Element` and `document`. Both reuse the v0.7.11 selector machinery -- they're typed wrappers around `find_all_descendants` with the input rewritten as a selector string. Empty / whitespace-only inputs short-circuit to an empty NodeList without invoking the matcher (spec requires this; the underlying matcher would otherwise match everything). Seventh sub-crate of a Servo-replacement webview runtime targeting Tauri.
docs.rs failed to build web-api-cat-0.7.14
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.

web-api-cat

Bindings between boa-cat (JS engine) and html-cat (DOM) + net-cat (HTTP), exposing document, Element methods, and fetch as boa-cat NativeFns so scripts can read/mutate a parsed HTML document and make synchronous HTTP requests.

web-api-cat is the seventh sub-crate of a comp-cat-rs Servo-replacement webview runtime targeting Tauri integration. Same framework constraints as the rest of the stack: no mut, no Rc/Arc, no interior mutability, no panics.

Example

use boa_cat::{evaluate_program_with, fuel::Fuel, env::Env, heap::Heap};
use ecma_lex_cat::lex;
use ecma_parse_cat::parse_script;
use web_api_cat::install;

fn main() -> Result<(), web_api_cat::Error> {
    let html = html_cat::parse("<html><body><p id='greet'>hello</p></body></html>")?;
    let (env, heap) = install(Env::empty(), Heap::new(), &html);
    let tokens = lex("document.getElementById('greet').textContent")
        .map_err(boa_cat::Error::from)?;
    let program = parse_script(&tokens).map_err(boa_cat::Error::from)?;
    let (value, _heap) = evaluate_program_with(&program, env, heap, Fuel::new(100_000))?;
    assert_eq!(format!("{value}"), "\"hello\"");
    Ok(())
}

v0 scope

  • document.getElementById(id) -- walks the document tree, returns the matching element-object or null.
  • document.querySelector(selector) -- limited subset (tag, .class, #id, tag.class, tag#id).
  • Element properties: tagName, id, className, textContent, children array.
  • Element methods: getAttribute(name), setAttribute(name, value), hasAttribute(name).
  • fetch(url) -- synchronous net-cat call returning { ok, status, statusText, text, headers }.

Deferred to v0.2+

  • Full CSS selector syntax in querySelector.
  • DOM mutation back-propagation to layout-cat / paint-cat.
  • Async fetch (Promise-based).
  • DOM mutation API (appendChild, removeChild, ...).
  • Computed style introspection.
  • Event API.
  • HTTPS support (waits on net-cat's TLS feature).

License

MIT OR Apache-2.0