Avae.Browser.Essentials 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Avae.Browser.Essentials --version 1.0.1
                    
NuGet\Install-Package Avae.Browser.Essentials -Version 1.0.1
                    
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="Avae.Browser.Essentials" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Avae.Browser.Essentials" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Avae.Browser.Essentials" />
                    
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 Avae.Browser.Essentials --version 1.0.1
                    
#r "nuget: Avae.Browser.Essentials, 1.0.1"
                    
#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 Avae.Browser.Essentials@1.0.1
                    
#: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=Avae.Browser.Essentials&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Avae.Browser.Essentials&version=1.0.1
                    
Install as a Cake Tool

Avae.Browser.Essentials

A port of Microsoft.Maui.Essentials tailored for Avalonia.Browser, bringing essential cross-platform APIs to your Avalonia-based browser applications. This package simplifies access to common device and application features, enabling seamless integration with web technologies.

Features

Cross-Platform Essentials: Leverage APIs from Microsoft.Maui.Essentials adapted for browser environments.

Automatic Integration: Includes essentials.js, automatically copied to your wwwroot folder during build.

Lightweight Configuration: Minimal setup required for integration into your Avalonia.Browser project.

MIT Licensed: Freely use, modify, and distribute under the permissive MIT License.

Getting Started

Follow these steps to integrate Avae.Browser.Essentials into your Avalonia.Browser project.

Prerequisites

An Avalonia.Browser project set up with .NET.

Installation

  1. Add Microsoft.Maui.Essentials to Your Shared Project

In your shared project�s .csproj file, include the Microsoft.Maui.Essentials package. Use one of the following methods

<UseMauiEssentials>true</UseMauiEssentials>

OR

<PackageReference Include="Microsoft.Maui.Essentials">
    <PrivateAssets>all</PrivateAssets>
</PackageReference>
  1. Configure the Avalonia.Browser Project

In your Avalonia.Browser project�s .csproj file, add the following to enable IndexedDB support for file operations:

<EmccExtraLDFlags>-lidbfs.js</EmccExtraLDFlags>
  1. Register Essentials in Your Application

Modify the Main method in your Avalonia.Browser project to initialize the essentials library:

private static Task Main(string[] args) => BuildAvaloniaApp()
    .WithInterFont()
    .StartBrowserAppAsync("out").ContinueWith(async t =>
    {
        await JSInitialize.Initialize();
    });
  1. Update main.js

Ensure your main.js file exports the .NET runtime correctly:

export const dotnetRuntime = await dotnet
    .withDiagnosticTracing(false)
    .withApplicationArgumentsFromQuery()
    .create();
  1. Set Up index.html

Configure your index.html file to include necessary metadata and scripts. Below is a sample configuration:

<!DOCTYPE html>
<html>
<head>
    <title>BrowserTest.Browser</title>
    <meta charset="UTF-8">
    
    <meta name="app-version" content="1.2.3" />
    <meta name="build-version" content="1.2.3" />
    <meta name="name" content="myApplicationName" />
    <meta name="package" content="myApplicationPackage" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">    
    <link rel="stylesheet" href="./app.css" />
</head>
<body style="margin: 0; overflow: hidden">
    <div id="out">
        <div class="avalonia-splash">
            <h2>
                Powered by
                <a href="https://www.avaloniaui.net/" target="_blank">
                    <svg width="266" height="52" viewBox="0 0 266 52" fill="none" xmlns="http://www.w3.org/2000/svg">
                        
                    </svg>
                </a>
            </h2>
        </div>
    </div>
    <script type='module' src="./main.js"></script>
    <script>
        // To return the token when calling the WebAuthenticator
        const channel = new BroadcastChannel('token');
        channel.postMessage(window.location.href);

        // Optionally, close the callback page after sending the token
        if (/Android|iPhone/i.test(navigator.userAgent)) {
            if (window.opener)
                window.close();
        }
        else
            window.close();
    </script>
</body>
</html>

Configuration

No additional configuration is required. The essentials.js file is automatically copied to your wwwroot folder during the build process, ensuring seamless integration.

Usage

Once installed, you can use Microsoft.Maui.Essentials APIs within your Avalonia.Browser application. For example, access application information via AppInfo or handle web authentication with WebAuthenticator.

Example: Accessing AppInfo

using Microsoft.Maui.Essentials;

string appName = AppInfo.Name; // Retrieves "myApplicationName" from index.html
string appVersion = AppInfo.VersionString; // Retrieves "1.2.3"

Built With

This package builds upon the excellent work of:

Microsoft.Maui.Essentials

AvaloniaUI

BlazorBrowserDetect

License

Avae.Browser.Essentials is licensed under the MIT License.

Contributing

Contributions are welcome! Please submit issues or pull requests to the GitHub repository. Ensure your code follows the project�s coding standards.

Acknowledgments

Thanks to the Avalonia team for their robust UI framework.

Gratitude to the MAUI team for providing cross-platform essentials.

Product Compatible and additional computed target framework versions.
.NET net8.0-browser1.0 is compatible.  net9.0-browser was computed.  net10.0-browser was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0-browser1.0

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 136 8/20/2025
1.0.1 106 8/17/2025
1.0.0 108 8/16/2025