Skip to content

The extensible library that uses client hints and user agent to detect browser, device, platform and architecture.

License

Notifications You must be signed in to change notification settings

Optivify/BrowserDetection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

BrowserDetection

The extensible library that uses client hints and user agent to detect browser, device, platform and architecture.

Usage

1. Install the package.

Install-Package Optivify.BrowserDetection

2. Register the browser detection services in Program.

var builder = WebApplication.CreateBuilder(args);
var services = builder.Services;
var configuration = builder.Configuration;
// Add browser detection
services.AddBrowserDetection(configuration);

3. Use IDetectionService by injecting in controller constructor or in the view file.

Use the service in controller:

    public class HomeController : Controller
    {
        private readonly IDetectionService detectionService;
        
        public HomeController(IDetectionService detectionService)
        {
            this.detectionService = detectionService;
        }
        
        public IActionResult Index()
        {
            var browserName = this.detectionService.Browser.Name;
            var browserVersion = this.detectionService.Browser.Version;

            return View();
        }
    }

Use the service in view:

@using Optivify.BrowserDetection.Services
@inject IDetectionService detectionService
@detectionService.Browser.Name

Sample Project

You can find the sample project in the folder src/Samples/Optivify.BrowserDetection.Samples.Web.AspNetCore. The online detection: https://detection.optivify.com