Live Chat Icon For mobile
Live Chat Icon

How do you get a user agent in Blazor WebAssembly?

Platform: Blazor| Category : General, JavaScript Interop

Get a user agent in Blazor WebAssembly using JavaScript Interop with the navigator.userAgent property.


@page "/"
@inject IJSRuntime JsRuntime


@code {

    private string userAgent { get; set; }

    protected override async Task OnInitializedAsync()
        userAgent = await JsRuntime.InvokeAsync<string>("getUserAgent");


      . . . 
      . . . 
        window.getUserAgent = () => {
            return navigator.userAgent;
</body > 

View Sample in GitHub

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.