Skip to main content

Crate blitz_script

Crate blitz_script 

Source
Expand description

JavaScript execution on top of Blitz

This crate implements a ScriptDocument: a wrapper around a BaseDocument which can execute the JavaScript contained in (or referenced by) the document’s <script> tags using the Boa JavaScript engine, and which exposes JavaScript DOM APIs (document, elements, events, timers, etc) backed by blitz-dom to the scripts it runs.

It is capable of running real-world JavaScript frameworks such as Preact.

§Example

use blitz_script::ScriptDocument;
use blitz_dom::DocumentConfig;

let mut doc = ScriptDocument::from_html(
    r#"
        <div id="root"></div>
        <script>
            const el = document.createElement("h1");
            el.textContent = "Hello from JS";
            document.getElementById("root").appendChild(el);
        </script>
    "#,
    DocumentConfig::default(),
);
doc.execute_scripts();

Modules§

script_stats
What the JavaScript side costs, per frame.

Structs§

DefaultScriptFetcher
The default ScriptFetcher: supports file: and data: URLs.
ScriptDocument
A Document which executes the JavaScript contained in the document’s <script> tags, exposing DOM APIs backed by blitz-dom to the scripts.

Enums§

FetchError

Traits§

ScriptFetcher
Trait for synchronously fetching external script sources.