Skip to content

this.browser

Marcelo de Souza Lima edited this page Jan 17, 2025 · 2 revisions

Overview

The this.browser property provides basic information about the user's browser, including its name and version. This is useful for handling browser-specific logic in your application, such as applying workarounds for specific browsers or logging browser details for analytics.

Example Output

{
    "name": "Chrome",
    "version": "130.0.0.0",
    "major": "130"
}

Key Properties

  • name: The name of the browser (e.g., Chrome, Firefox, Safari).
  • version: The full version of the browser (e.g., 130.0.0.0).
  • major: The major version of the browser (e.g., 130).

Usage

To access the browser information, simply use this.browser in your class:

class MyApp extends JsBaseClass {
    async handle() {
        // Log browser details
        this.console.log('Browser Name:', this.browser.name);
        this.console.log('Browser Version:', this.browser.version);
        this.console.log('Browser Major Version:', this.browser.major);

        // Example: Apply browser-specific logic
        if (this.browser.name === 'Chrome' && parseInt(this.browser.major) >= 100) {
            this.console.log('Running on Chrome version 100 or above.');
        } else {
            this.console.log('Running on an older or different browser.');
        }
    }
}

// Initialize the app
const app = new MyApp();
app.init();

Notes

  • The browser detection is powered by the my-ua-parser library, which ensures accurate and up-to-date results.

Clone this wiki locally