JavaScript.Avalonia.ClearScript 11.3.4-alpha.4

This is a prerelease version of JavaScript.Avalonia.ClearScript.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package JavaScript.Avalonia.ClearScript --version 11.3.4-alpha.4
                    
NuGet\Install-Package JavaScript.Avalonia.ClearScript -Version 11.3.4-alpha.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JavaScript.Avalonia.ClearScript" Version="11.3.4-alpha.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JavaScript.Avalonia.ClearScript" Version="11.3.4-alpha.4" />
                    
Directory.Packages.props
<PackageReference Include="JavaScript.Avalonia.ClearScript" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add JavaScript.Avalonia.ClearScript --version 11.3.4-alpha.4
                    
#r "nuget: JavaScript.Avalonia.ClearScript, 11.3.4-alpha.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package JavaScript.Avalonia.ClearScript@11.3.4-alpha.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=JavaScript.Avalonia.ClearScript&version=11.3.4-alpha.4&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=JavaScript.Avalonia.ClearScript&version=11.3.4-alpha.4&prerelease
                    
Install as a Cake Tool

JavaScript.Avalonia.ClearScript

ClearScript/V8 runtime for JavaScript.Avalonia. Applications reference and construct this runtime explicitly; the reusable DOM/browser-services package does not impose an engine. The repository's JavaScript Playground uses it for all script execution.

The runtime provides separate owner and virtual-iframe V8 contexts, a generic DOM callback adapter, and a typed-array Canvas2D command buffer that replays through the existing CanvasRenderingContext2D implementation.

using JavaScript.Avalonia;
using JavaScript.Avalonia.ClearScript;

using var host = new AvaloniaBrowserHost(window);
using var runtime = new ClearScriptV8Runtime(
    host,
    new ClearScriptV8RuntimeOptions
    {
        EnableTrustedSameOriginContextSharing = true
    });

runtime.Execute("require('./app.js');");

Multiple independent charts

ClearScriptV8RuntimeOptions.SharedCache defaults to the process-wide ClearScriptV8SharedCache.ProcessWide instance. Multiple runtimes therefore retain separate V8 globals, module exports, DOM documents, event callbacks, and disposal lifetimes while reusing immutable external-script source text and V8 code-cache bytes. This is the recommended shape for multiple complex JavaScript components: one host/runtime per chart and one shared cache for the application.

var sharedCache = new ClearScriptV8SharedCache();

foreach (var chartRoot in chartRoots)
{
    var host = CreateHostFor(chartRoot);
    var runtime = new ClearScriptV8Runtime(
        host,
        new ClearScriptV8RuntimeOptions
        {
            EnableTrustedSameOriginContextSharing = true,
            SharedCache = sharedCache
        });
    chartSessions.Add((host, runtime));
}

Do not share a chart's mutable exports, window, document, or vendor widget object with another chart. Sharing one V8 isolate would couple heap pressure, security tokens, and failure/disposal behavior. The bounded source/code cache captures the compilation win without that coupling. Set SharedCache = null only for diagnostic A/B comparison; GetMetrics() exposes hit, miss, accepted/verified/updated, entry, and byte counts.

Background precompilation and persistence

Applications with several charts should prepare immutable compilation units in parallel, then create and execute each chart runtime on Avalonia's UI thread. The runtime provides a single-flight gate per content key: concurrent requests for the same source elect one compiler and the other callers reuse its result. It never shares globals, CommonJS exports, DOM nodes, or callbacks.

var cache = new ClearScriptV8SharedCache(new ClearScriptV8SharedCacheOptions
{
    PersistentDirectory = Path.Combine(appCacheDirectory, "v8"),
    CompatibilityTag = reviewedNativeBuildIdentity,
    MaxPersistentEntries = 4096,
    MaxPersistentBytes = 768L * 1024 * 1024
});

var sources = new[]
{
    new V8CompilationSource("app.js", appSource),
    ClearScriptV8Runtime.CreateCommonJsCompilationSource(modulePath, moduleSource)
};
await ClearScriptV8Runtime.PrecompileAsync(cache, sources, cancellationToken: token);

PrecompileAsync performs V8 cache generation on a thread-pool thread. Source loading can also be partitioned across workers, as the Playground does. Actual script execution that can call the Avalonia DOM remains UI-thread-affine. Arbitrary synchronous JavaScript cannot be paused and resumed safely, so this API does not claim to move DOM evaluation off-thread.

Persistent entries contain only V8 code-cache bytes. Their keys use the exact document name and SHA-256 source content; the compatibility directory also covers the cache schema, ClearScript managed assembly identity, RID, process architecture, and optional application/native-build tag. Writes use a unique temporary file followed by atomic replacement. Headers and payload hashes are validated, corrupt entries are deleted and recompiled, and V8 remains the final validator through its accepted/verified/updated result. Entry and byte limits bound both memory and disk storage.

Clear() drops memory and metrics while preserving disk data. ClearPersistent() is the explicit destructive operation. The process-wide cache remains memory-only unless HTMLML_V8_CACHE_DIRECTORY is set; applications can instead construct and own a cache as above. GetMetrics() includes disk I/O and single-flight leader/waiter counters.

Single-flight is deliberately process-local. Separate application processes can both compile the same brand-new key, but unique temporary files and atomic replacement keep their concurrent writes valid; a later process consumes the resulting entry normally. This avoids an operating-system lock on normal runtime compilation. Multiple chart instances inside one application—the primary use case—share the exact single-flight gate and never generate the same content key twice.

Experimental native requirement

Virtual iframes exchange direct JavaScript objects only when ClearScript gives the contexts in this dedicated runtime a shared security token. Stock ClearScript 7.5.1 rejects that access. The exact proof patch is documented under third-party/clearscript-patches/.

EnableTrustedSameOriginContextSharing is deliberately disabled by default. Enable it only for contexts that the application treats as one trusted same-origin group. The runtime does not attach an external iframe factory without this explicit option.

Before production use, ship reviewed native builds for each supported RID, retain default isolation for unrelated runtimes, and validate native memory and disposal on every target platform.

This managed package intentionally depends on Microsoft.ClearScript.V8 rather than Microsoft.ClearScript.Complete. The complete package supplies Microsoft's stock native binaries for every RID and could bypass HtmlML's reviewed context-sharing patch. Reference the RID-specific JavaScript.Avalonia.ClearScript.Native.<rid> package for a reviewed deployment, or provide the validated native path/RID explicitly during local development. The native package includes the exact patch, source/V8 provenance, and SHA-256 metadata; see third-party/clearscript-patches/README.md.

Playground default

The sample compiles this package and uses V8 without an engine-selection flag. See samples/JavaScriptPlayground/README.md for native-path, build, and run commands.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on JavaScript.Avalonia.ClearScript:

Package Downloads
HtmlML.Sdk.Avalonia

Avalonia control host for packaged HtmlML React and TypeScript components.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.3.4-alpha.6 59 7/24/2026
11.3.4-alpha.4 58 7/24/2026
11.3.4-alpha.3 56 7/23/2026
1.0.17 829 8/1/2026
1.0.15 700 8/1/2026
1.0.14 686 7/31/2026
1.0.11 667 7/30/2026
1.0.9 673 7/30/2026
1.0.8 869 7/28/2026
1.0.7 879 7/28/2026
1.0.6 872 7/27/2026
1.0.5 886 7/27/2026
1.0.2 883 7/27/2026
1.0.1 917 7/27/2026
1.0.0 913 7/27/2026