Navigator
How to use the Navigator class of the bit Butil?
Usage
To use the browser navigator features you need to inject the Bit.Butil.Navigator class and use it like this:
@inject Bit.Butil.Navigator navigator
@code {
var userAgent = await navigator.GetUserAgent();
}Methods
GetDeviceMemory:
Returns the amount of device memory in gigabytes. This value is an approximation given by rounding to the nearest power of 2 and dividing that number by 1024 (MDN).
@inject Bit.Butil.Navigator navigator
<BitButton OnClick="@GetDeviceMemory">GetDeviceMemory</BitButton>
<div>Device memory is: @deviceMemory</div>
@code {
private string? deviceMemory;
private async Task GetDeviceMemory()
{
var result = await navigator.GetDeviceMemory();
deviceMemory = result.ToString();
}
}GetHardwareConcurrency:
Returns the number of logical processor cores available (MDN).
@inject Bit.Butil.Navigator navigator
<BitButton OnClick="@GetHardwareConcurrency">GetHardwareConcurrency</BitButton>
<div>Hardware concurrency is: @hardwareConcurrency</div>
@code {
private string? hardwareConcurrency;
private async Task GetHardwareConcurrency()
{
var result = await navigator.GetHardwareConcurrency();
hardwareConcurrency = result.ToString();
}
}GetLanguage:
Returns a string representing the preferred language of the user, usually the language of the browser UI. The null value is returned when this is unknown (MDN).
@inject Bit.Butil.Navigator navigator
<BitButton OnClick="@GetLanguage">GetLanguage</BitButton>
<div>Language: @language</div>
@code {
private string? language;
private async Task GetLanguage()
{
var result = await navigator.GetLanguage();
language = result.ToString();
}
}GetLanguages:
Returns an array of strings representing the languages known to the user, by order of preference (MDN).
@inject Bit.Butil.Navigator navigator
<BitButton OnClick="@GetLanguages">GetLanguages</BitButton>
<div>Languages: @languages</div>
@code {
private string? languages;
private async Task GetLanguages()
{
var result = await navigator.GetLanguages();
languages = string.Join(",", result);
}
}GetMaxTouchPoints:
Returns the maximum number of simultaneous touch contact points are supported by the current device (MDN).
@inject Bit.Butil.Navigator navigator
<BitButton OnClick="@GetMaxTouchPoints">GetMaxTouchPoints</BitButton>
<div>Max touch points: @maxTouchPoints</div>
@code {
private string? maxTouchPoints;
private async Task GetMaxTouchPoints()
{
var result = await navigator.GetMaxTouchPoints();
maxTouchPoints = result.ToString();
}
}IsOnLine:
Returns a boolean value indicating whether the browser is working online (MDN).
@inject Bit.Butil.Navigator navigator
<BitButton OnClick="@GetIsOnLine">GetIsOnLine</BitButton>
<div>Is OnLine: @isOnLine</div>
@code {
private string? isOnLine;
private async Task GetIsOnLine()
{
var result = await navigator.IsOnLine();
isOnLine = result.ToString();
}
}IsPdfViewerEnabled:
Returns true if the browser can display PDF files inline when navigating to them, and false otherwise (MDN).
@inject Bit.Butil.Navigator navigator
<BitButton OnClick="@GetIsPdfViewerEnabled">GetIsPdfViewerEnabled</BitButton>
<div>Is Pdf viewer enabled: @isPdfViewerEnabled</div>
@code {
private string? isPdfViewerEnabled;
private async Task GetIsPdfViewerEnabled()
{
var result = await navigator.IsPdfViewerEnabled();
isPdfViewerEnabled = result.ToString();
}
}GetUserAgent:
Returns the user agent string for the current browser (MDN).
@inject Bit.Butil.Navigator navigator
<BitButton OnClick="@GetUserAgent">GetUserAgent</BitButton>
<div>User agent: @userAgent</div>
@code {
private string? userAgent;
private async Task GetUserAgent()
{
var result = await navigator.GetUserAgent();
userAgent = result.ToString();
}
}IsWebDriver:
Indicates whether the user agent is controlled by automation (MDN).
CanShare:
Returns true if a call to navigator.Share() would succeed (MDN).
@inject Bit.Butil.Navigator navigator
<BitButton OnClick="@GetCanShare">GetCanShare</BitButton>
<div>Can share: @canShare</div>
@code {
private string? canShare;
private async Task CanShare()
{
var result = await navigator.CanShare();
canShare = result.ToString();
}
}ClearAppBadge:
Clears a badge on the current app's icon and returns a Promise that resolves with undefined (MDN).
@inject Bit.Butil.Navigator navigator <BitButton OnClick="@(() => navigator.ClearAppBadge())">ClearAppBadge</BitButton>
SendBeacon:
Used to asynchronously transfer a small amount of data using HTTP from the User Agent to a web server (MDN).
@inject Bit.Butil.Navigator navigator <BitButton OnClick="@(() => navigator.SendBeacon())">SendBeacon</BitButton>
SetAppBadge:
Sets a badge on the icon associated with this app and returns a Promise that resolves with undefined (MDN).
@inject Bit.Butil.Navigator navigator <BitButton OnClick="@(() => navigator.SetAppBadge())">SetAppBadge</BitButton>
Share:
Invokes the native sharing mechanism of the current platform (MDN).
@inject Bit.Butil.Navigator navigator
<BitTextField @bind-Value="textValue" Label="Text" />
<BitTextField @bind-Value="titleValue" Label="Title" />
<BitTextField @bind-Value="urlValue" Label="Url" />
<BitButton OnClick="Share">Share</BitButton>
@code {
private string? textValue;
private string? titleValue;
private string? urlValue;
private async Task Share()
{
var shareData = new ShareData()
{
Text = textValue,
title = titleValue,
url = urlValue
};
await navigator.Share(shareData);
}
}Vibrate:
Causes vibration on devices with support for it. Does nothing if vibration support isn't available (MDN).
@inject Bit.Butil.Navigator navigator
<BitButton OnClick="@(() => navigator.Vibrate(sosPattern))">Vibrate</BitButton>
@code {
private int[] sosPattern = [100, 30, 100, 30, 100, 30, 200, 30, 200, 30, 200, 30, 100, 30, 100, 30, 100];
}