loading

Device and hardware

GetDeviceMemory / GetHardwareConcurrency / GetMaxTouchPoints

Coarse hardware hints for adaptive experiences: approximate RAM in gigabytes, the number of logical CPU cores, and how many simultaneous touch points the device supports.

C#
float memory = await navigator.GetDeviceMemory();        // e.g. 8
float cores = await navigator.GetHardwareConcurrency();  // e.g. 12
byte touchPoints = await navigator.GetMaxTouchPoints();  // 0 on most desktops
Live sample
hardware output
Results will appear here when you interact with the samples.

Language and browser traits

GetLanguage / GetLanguages / GetUserAgent / IsPdfViewerEnabled / IsWebDriver

Read the user's preferred languages in priority order, the raw user-agent string, whether the browser renders PDFs inline, and whether the session is driven by automation such as Selenium or Playwright.

C#
string language = await navigator.GetLanguage();     // "en-US"
string[] languages = await navigator.GetLanguages(); // ["en-US", "en", ...]

string userAgent = await navigator.GetUserAgent();
bool pdfInline = await navigator.IsPdfViewerEnabled();
bool automated = await navigator.IsWebDriver();
Live sample
language and traits output
Results will appear here when you interact with the samples.

Online status

IsOnLine

Reports whether the browser believes it has network connectivity. A false value is trustworthy (definitely offline); true only means some network interface is up.

C#
bool online = await navigator.IsOnLine();
Live sample

Toggle DevTools network throttling to Offline and check again.

online status output
Results will appear here when you interact with the samples.

Pending input

IsInputPending

Asks whether the browser has user input waiting that this task is holding up - the check that turns a long loop into one that yields only when yielding would help. The demo runs a 600 ms busy loop that polls between chunks and yields whenever input is pending, then carries on; click somewhere while it runs. Experimental and Chromium-only: elsewhere it answers false, so treat it as a hint and always bound the loop with a deadline of your own.

C#
// IsInputPending only ever lets you yield *sooner*; a deadline is what
// guarantees you yield at all on a browser that always answers false
var nextYield = DateTime.UtcNow.AddMilliseconds(50);

while (thereIsMoreWork)
{
    DoAChunkOfWork();

    if (await navigator.IsInputPending() || DateTime.UtcNow >= nextYield)
    {
        await Task.Yield();   // let the browser answer the user first
        nextYield = DateTime.UtcNow.AddMilliseconds(50);
    }
}

// includeContinuous also counts mousemove, pointermove, wheel and drag -
// which fire constantly, so leave it false unless the work is truly interruptible
bool anyPointerMovement = await navigator.IsInputPending(includeContinuous: true);
Live sample
pending input output
Results will appear here when you interact with the samples.

Web Share

CanShare / Share / ShareFiles

Invokes the platform's native share sheet with a title, text and URL. Check CanShare first, and use ShareFiles to attach one or more files on browsers that support Web Share Level 2.

C#
if (await navigator.CanShare())
{
    await navigator.Share(new ShareData
    {
        Title = "Bit.Butil",
        Text = "Browser APIs for C# developers",
        Url = "https://bitplatform.dev",
    });
}

bool shared = await navigator.ShareFiles(
    "Report",
    [new ShareFile { Name = "report.txt", MimeType = "text/plain", Data = bytes }],
    text: "Monthly report");
Live sample
web share output
Results will appear here when you interact with the samples.

App badge

SetAppBadge / ClearAppBadge

Shows a count (or a plain dot when no number is given) on the app icon of an installed PWA - the same affordance native apps use for unread counts.

C#
await navigator.SetAppBadge(7);   // show "7" on the app icon
await navigator.SetAppBadge();    // show a generic dot

await navigator.ClearAppBadge();  // remove the badge
Live sample
Badge count
app badge output
Results will appear here when you interact with the samples.

Beacon and vibration

SendBeacon / Vibrate

SendBeacon queues a small fire-and-forget HTTP POST that survives page unload - the reliable way to flush analytics. Vibrate plays a pattern of vibration/pause durations in milliseconds on supporting hardware.

C#
bool queued = await navigator.SendBeacon("/api/analytics", "{\"event\":\"page-close\"}");

bool accepted = await navigator.Vibrate([200, 100, 200]);
Live sample

Vibration only has a physical effect on devices with a vibration motor.

beacon and vibration output
Results will appear here when you interact with the samples.
Warning:
Secure context and user gesture requiredShare, ShareFiles and the app badge APIs require a secure context (https), and sharing must be triggered by a user gesture such as a button click. The share sheet is mostly a mobile affordance - many desktop browsers reject it - and badges only appear on installed PWAs.

API reference

Member
Signature
Description
GetDeviceMemory
Task<float> GetDeviceMemory()
Approximate device memory in gigabytes (rounded to a power of 2).
GetHardwareConcurrency
Task<float> GetHardwareConcurrency()
Number of logical processor cores available.
GetLanguage
Task<string> GetLanguage()
The user's preferred language, usually the browser UI language.
GetLanguages
Task<string[]> GetLanguages()
The user's known languages, ordered by preference.
GetMaxTouchPoints
Task<byte> GetMaxTouchPoints()
Maximum number of simultaneous touch contact points supported.
IsOnLine
Task<bool> IsOnLine()
Whether the browser is working online.
IsPdfViewerEnabled
Task<bool> IsPdfViewerEnabled()
True when the browser can display PDF files inline.
GetUserAgent
Task<string> GetUserAgent()
The raw user-agent string of the current browser.
IsWebDriver
Task<bool> IsWebDriver()
True when the user agent is controlled by automation.
CanShare
Task<bool> CanShare()
True when a Share call would succeed. An overload accepts a ShareData payload to validate specific content.
Share
Task Share(ShareData data)
Invokes the native share mechanism with title, text and url.
ShareFiles
Task<bool> ShareFiles(string? title, ShareFile[] files, string? text = null, string? url = null)
Web Share Level 2: shares files alongside optional title, text and url; false when the set cannot be shared.
SetAppBadge
Task SetAppBadge(int? contents = null)
Sets a numeric badge (or a generic dot) on the installed app's icon.
ClearAppBadge
Task ClearAppBadge()
Removes the badge from the app icon.
SendBeacon
Task<bool> SendBeacon(string url, object? data = null)
Queues a small asynchronous HTTP transfer that survives page unload; true when queued.
Vibrate
Task<bool> Vibrate(int[] pattern)
Plays a vibration/pause pattern (ms) on supporting devices; no-op elsewhere.
IsCookieEnabled
Task<bool> IsCookieEnabled()
Whether the browser accepts cookies at all. Reports the global setting, not whether this document can set one - a third-party iframe with partitioned cookies still reads true. Use StorageAccess for that question.
GetDoNotTrack
Task<string?> GetDoNotTrack()
The user's Do Not Track preference: 1, 0, or null when unset. Being removed from browsers, so treat null as no signal rather than as consent.
GetUserActivation
Task<UserActivationState?> GetUserActivation()
Whether the user has interacted with the page and whether that interaction is still spendable. Null on browsers without navigator.userActivation.
IsInputPending
Task<bool> IsInputPending(bool includeContinuous = false)
Whether the browser has user input waiting that this task is holding up. Poll it between chunks of a long loop and yield when it says yes. Experimental and Chromium-only - it answers false everywhere else, so it is a hint that lets you yield sooner, never the thing that ends the loop: bound that with a deadline.
UserActivationState
class UserActivationState { bool HasBeenActive; bool IsActive; }
Sticky activation (has ever interacted) and transient activation (recent enough for a gesture-gated API). Check IsActive before calling one, to fail fast with your own message instead of an opaque browser rejection.
CanRegisterProtocolHandler
Task<bool> CanRegisterProtocolHandler()
True when the runtime implements registerProtocolHandler.
RegisterProtocolHandler
Task<bool> RegisterProtocolHandler(string scheme, string url)
Offers this site as the handler for a URL scheme. The url must be same-origin and contain a single %s placeholder. False when the scheme or the url was rejected.
UnregisterProtocolHandler
Task<bool> UnregisterProtocolHandler(string scheme, string url)
Removes a registration. Non-standard and Chromium-only; false elsewhere, where the user removes it from site settings instead.
CanGetInstalledRelatedApps
Task<bool> CanGetInstalledRelatedApps()
True when the runtime implements getInstalledRelatedApps.
GetInstalledRelatedApps
Task<RelatedApp[]> GetInstalledRelatedApps()
The installed subset of the manifest's related_applications. Empty when none are installed or the manifest declares none.
RelatedApp
class RelatedApp { string Id; string Platform; string Url; string Version; }
One installed related app: its platform-specific id, the platform (play, windows, webapp…), its URL and its version.
An unhandled error has occurred. Reload 🗙