Meziantou.Framework.WebPlatform.JavaScript 1.0.14

Prefix Reserved
dotnet add package Meziantou.Framework.WebPlatform.JavaScript --version 1.0.14
                    
NuGet\Install-Package Meziantou.Framework.WebPlatform.JavaScript -Version 1.0.14
                    
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="Meziantou.Framework.WebPlatform.JavaScript" Version="1.0.14" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Meziantou.Framework.WebPlatform.JavaScript" Version="1.0.14" />
                    
Directory.Packages.props
<PackageReference Include="Meziantou.Framework.WebPlatform.JavaScript" />
                    
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 Meziantou.Framework.WebPlatform.JavaScript --version 1.0.14
                    
#r "nuget: Meziantou.Framework.WebPlatform.JavaScript, 1.0.14"
                    
#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 Meziantou.Framework.WebPlatform.JavaScript@1.0.14
                    
#: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=Meziantou.Framework.WebPlatform.JavaScript&version=1.0.14
                    
Install as a Cake Addin
#tool nuget:?package=Meziantou.Framework.WebPlatform.JavaScript&version=1.0.14
                    
Install as a Cake Tool

Meziantou.Framework.WebPlatform.JavaScript

Runs the scripts of the documents of Meziantou.Framework.WebPlatform with Meziantou.Framework.JavaScriptEngine: a ScriptEngine with the WebIDL bindings of the DOM.

using var engine = new JavaScriptScriptEngine(new JavaScriptScriptEngineOptions
{
    Timeout = TimeSpan.FromSeconds(5), // per script or callback
});

using var context = new BrowsingContext(new BrowsingContextOptions
{
    ScriptEngine = engine,
    DocumentLoader = DocumentLoader.Create(), // optional: external scripts, modules, fetch, XMLHttpRequest, WebSocket, EventSource...
    UnhandledScriptError = (_, error) => Console.Error.WriteLine(error),
    ConsoleMessage = (_, message) => Console.WriteLine(message.Text), // console.log(), console.count()...
});

var document = await context.NavigateAsync("https://example.com/", _ => """
    <title>Example</title>
    <ul id=list></ul>
    <script>
      setTimeout(() => document.getElementById('list').innerHTML = '<li>a<li>b', 100);
    </script>
    """);

// Run the tasks and the timers until there is nothing left
do { await context.EventLoop.RunUntilIdleAsync(); } while (await context.EventLoop.WaitForNextTimerAsync());

Assert.Equal("<li>a</li><li>b</li>", document.GetElementById("list")!.InnerHtml);

// Evaluate code in the realm of a window
var title = engine.Evaluate(context.Window, "document.title");
Assert.Equal("Example", title.AsString());

The windows of the browsing contexts that use an engine share its JsEngine (the similar-origin window agent); each window is the global object of its own realm. A worker gets its own engine, with the same options, on its own thread. JavaScriptScriptEngineOptions limits the resources of each entry into JavaScript (a script, an event listener, a timer callback...): Timeout (10 seconds by default), MemoryLimit (256 MB allocated by default), MaxStatements, RecursionLimit (512 calls by default; null is the limit of the engine, 10,000 calls) and RegexTimeout. TimeProvider is the clock of Date, and ConfigureEngine sets the other options of the engine (e.g. the time zone and the default locale of Intl). ScriptCache reuses the parsed classic scripts across the documents and the engines (JavaScriptScriptCache.Shared, bounded to 8 million characters of source text, by default; null disables it): a page loaded again is not parsed again, and its hot functions are not compiled again. The scripts only see the DOM and the JavaScript built-ins: the engine has no access to .NET types.

A subclass can add its own functions to the global objects in OnRealmCreated:

/// <summary>A script engine whose windows have a <c>hostAdd</c> function.</summary>
private sealed class HostFunctionsScriptEngine : JavaScriptScriptEngine
{
    protected override void OnRealmCreated(GlobalScope global, JsObject globalObject)
    {
        var realm = Engine.CurrentRealm!;
        globalObject.SetProperty("hostAdd", realm.CreateFunction("hostAdd", 2, (_, arguments) => arguments[0].AsNumber() + arguments[1].AsNumber()));
    }
}

See scripting.md for the threat model and the integration with the processing model of the HTML Standard.

Product Compatible and additional computed target framework versions.
.NET 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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Meziantou.Framework.WebPlatform.JavaScript:

Package Downloads
Meziantou.Framework.WebPlatform.DevTools

A Chrome DevTools Protocol (CDP) server for Meziantou.Framework.WebPlatform: Playwright (connectOverCDP), Puppeteer and the other CDP clients automate the managed browser engine as a Chromium browser.

Meziantou.AspNetCore.Testing

Tests of ASP.NET Core applications and Blazor components in a managed browser engine (Meziantou.Framework.WebPlatform): Blazor components rendered in a real DOM, and the pages of an application in memory (MVC, Razor Pages, Blazor, minimal APIs...), with CSS layout, scripts, user input (mouse, keyboard, touch), DOM and accessibility snapshots, and screenshots.

Meziantou.Framework.WebPlatform.Playwright

A Playwright server for Meziantou.Framework.WebPlatform: the Playwright clients (.NET, Node.js, Python, Java) connect to it with BrowserType.ConnectAsync and automate the managed browser engine (navigation, locators, actions, assertions, screenshots, network interception).

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.14 0 11/29/2026
1.0.13 122 11/22/2026
1.0.12 148 11/20/2026
1.0.11 118 11/18/2026
1.0.10 127 11/15/2026
1.0.9 166 11/14/2026
1.0.8 124 11/13/2026
1.0.7 104 11/13/2026
1.0.6 123 11/8/2026
1.0.5 147 11/5/2026
1.0.4 265 10/25/2026
1.0.3 176 10/25/2026
1.0.2 107 10/24/2026
1.0.1 112 10/21/2026
1.0.0 114 10/21/2026