Package com.smartgwt.client.util

# Class Browser

java.lang.Object
com.smartgwt.client.util.Browser

public class Browser extends Object
The `Browser` class contains various class attributes that indicate basic properties of the browser and whether certain features are enabled.

These flags represent a "best effort" at browser detection based on the user agent string and other indicators. Browser detection is inherently imperfect - browsers may spoof their user agent, new browser versions may change behavior, and unusual browser configurations may not be detected correctly. These properties should not be considered a fully supported API for all edge cases - applications with unusual browser compatibility requirements may need to implement their own detection logic.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Browser()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `checkMicStatus()`
  Refreshes `micAvailable` and `micPermission` by re-querying the browser's device list and permission state.
  `static void`
  `checkMicStatus(Function callback)`
  Refreshes `micAvailable` and `micPermission` by re-querying the browser's device list and permission state.
  `static void`
  `checkSpeechRecognition()`
  Tests whether the browser's SpeechRecognition implementation can successfully contact the vendor-operated speech-to-text service it depends on, and updates `allowsSpeechRecognition`, `micAvailable`, and `micPermission` accordingly.
  `static void`
  `checkSpeechRecognition(Function callback)`
  See `checkSpeechRecognition()`
  `static void`
  `checkSpeechRecognition(Function callback, Integer delay)`
  Tests whether the browser's SpeechRecognition implementation can successfully contact the vendor-operated speech-to-text service it depends on, and updates `allowsSpeechRecognition`, `micAvailable`, and `micPermission` accordingly.
  `static int`
  `getDefaultFontIncrease()`
  Preferred font size increase if none is specified.
  `static int`
  `getDefaultSizeIncrease()`
  Preferred control size increase if none is specified.
  `static String`
  `getDefaultSkin()`
  Preferred default skin if none is specified.
  `static boolean`
  `getIsDesktop()`
  Is the application running in a desktop browser? This is true if `isTablet` and `isHandset` are both `false`.
  `static boolean`
  `getIsHandset()`
  Is the application running on a handset-sized device, with a typical screen width of around 3-4 inches?
  `static boolean`
  `getIsMultiWindow()`
  Are the `MultiWindow` APIs supported and cross-window optimizations enabled? By default this is true in the `main window` if `OpenFin` is loaded, false otherwise.
  `static boolean`
  `getIsOpenFin()`
  Are we in an OpenFin environment? See class OpenFin for ways to call OpenFin methods from within Smart GWT.
  `static boolean`
  `getIsTablet()`
  Is the application running on a tablet device (e.g.
  `static boolean`
  `getIsTouch()`
  Is the application running on a touch device (e.g.
  `static boolean`
  `getSupportsFlatSkins()`
  Whether browser is capable of rendering flat skins (e.g.
  `static boolean`
  `hasLocalStorage()`
  Returns whether localStorage is accessible in the current environment.
  `static boolean`
  `hasSessionStorage()`
  Returns whether sessionStorage is accessible in the current environment.
  `static void`
  `setIsDesktop(boolean isDesktop)`
  Setter for `isDesktop` to allow this global variable to be changed at runtime.
  `static void`
  `setIsHandset(boolean isHandset)`
  Setter for `isHandset` to allow this global variable to be changed at runtime.
  `static void`
  `setIsMultiWindow(boolean isMultiWindow)`
  Sets a non-default value for `isMultiWindow`, such as enabling it even if `OpenFin` isn't present.
  `static void`
  `setIsTablet(boolean isTablet)`
  Setter for `isTablet` to allow this global variable to be changed at runtime.
  `static void`
  `setIsTouch(boolean isTouch)`
  Setter for `isTouch` to allow this global variable to be changed at runtime.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Browser

    public Browser()

- ## Method Details

  - ### getDefaultFontIncrease

    public static int getDefaultFontIncrease()
    Preferred font size increase if none is specified.
    Returns:
      current value of defaultFontIncrease

  - ### getDefaultSizeIncrease

    public static int getDefaultSizeIncrease()
    Preferred control size increase if none is specified.
    Returns:
      current value of defaultSizeIncrease

  - ### getDefaultSkin

    public static String getDefaultSkin()
    Preferred default skin if none is specified.
    Returns:
      current value of defaultSkin

  - ### getIsDesktop

    public static boolean getIsDesktop()
    Is the application running in a desktop browser? This is true if `isTablet` and `isHandset` are both `false`.
    Returns:
      current value of isDesktop

  - ### getIsHandset

    public static boolean getIsHandset()
    Is the application running on a handset-sized device, with a typical screen width of around 3-4 inches?

    This typically implies that the application will be working with only 300-400 pixels.

    Returns:
      current value of isHandset

  - ### getIsMultiWindow

    public static boolean getIsMultiWindow()
    Are the `MultiWindow` APIs supported and cross-window optimizations enabled? By default this is true in the `main window` if `OpenFin` is loaded, false otherwise. In `child windows`, this property is read-only, and assumes the value from the main window.

    Note: `MultiWindow` is currently an experimental feature and not supported except by special arrangement

    Returns:
      current value of isMultiWindow

  - ### getIsOpenFin

    public static boolean getIsOpenFin()
    Are we in an OpenFin environment? See class OpenFin for ways to call OpenFin methods from within Smart GWT.
    Returns:
      current value of isOpenFin

  - ### getIsTablet

    public static boolean getIsTablet()
    Is the application running on a tablet device (e.g. iPad, Nexus 7)?

    Smart GWT can correctly determine whether the device is a tablet in most cases. On any uncommon device for which this variable is incorrect, you can define the `isc_isTablet` global with the correct value, and Smart GWT will use `isc_isTablet` for `Browser.isTablet` instead of its own detection logic. Alternatively, you can use `setIsTablet()` to change this global variable before any components are created.

    The value of this variable is only meaningful on touch devices.

    Returns:
      current value of isTablet

  - ### getIsTouch

    public static boolean getIsTouch()
    Is the application running on a touch device (e.g. iPhone, iPad, Android device, etc.)?

    Smart GWT's auto-detected value for `isTouch` can be overridden via `setIsTouch()`.

    Returns:
      current value of isTouch

  - ### getSupportsFlatSkins

    public static boolean getSupportsFlatSkins()
    Whether browser is capable of rendering flat skins (e.g. Tahoe).
    Returns:
      current value of supportsFlatSkins

  - ### checkMicStatus

    public static void checkMicStatus()
    Refreshes `micAvailable` and `micPermission` by re-querying the browser's device list and permission state. This is non-intrusive: it does not trigger a permissions dialog or activate the microphone.

    This check runs automatically at page load. Call it explicitly to pick up changes that occurred after load, such as a microphone being plugged in or the user changing site permissions via browser settings.

    The callback receives a single argument, an object with two properties:

    - `micAvailable` (Boolean) - whether a mic is present
    - `micPermission` (String) - the permission state, or null if the Permissions API is unavailable
    See Also:
      - `com.smartgwt.client.util.Browser#micAvailable`
      - `com.smartgwt.client.util.Browser#micPermission`
      - `checkSpeechRecognition()`

  - ### checkMicStatus

    public static void checkMicStatus(Function callback)
    Refreshes `micAvailable` and `micPermission` by re-querying the browser's device list and permission state. This is non-intrusive: it does not trigger a permissions dialog or activate the microphone.

    This check runs automatically at page load. Call it explicitly to pick up changes that occurred after load, such as a microphone being plugged in or the user changing site permissions via browser settings.

    The callback receives a single argument, an object with two properties:

    - `micAvailable` (Boolean) - whether a mic is present
    - `micPermission` (String) - the permission state, or null if the Permissions API is unavailable
    Parameters:
      `callback` - called when the check completes
    See Also:
      - `com.smartgwt.client.util.Browser#micAvailable`
      - `com.smartgwt.client.util.Browser#micPermission`
      - `checkSpeechRecognition()`

  - ### checkSpeechRecognition

    public static void checkSpeechRecognition()
    Tests whether the browser's SpeechRecognition implementation can successfully contact the vendor-operated speech-to-text service it depends on, and updates `allowsSpeechRecognition`, `micAvailable`, and `micPermission` accordingly.

    This method is intrusive: it calls `getUserMedia({audio:true})`, which activates the microphone, shows browser recording-chrome, and may trigger a permissions dialog if the user has not already granted microphone access. It then starts a short throwaway SpeechRecognition session to detect browsers (such as Brave) that expose the API but block the underlying service.

    `VoiceAssist` calls this method on the user's first triple-tap to activate voice input. If the probe fails, VoiceAssist shows an explanatory message and does not enable. The result is cached, so subsequent triple-taps skip the probe. Developers may also call this method independently - for example, to decide whether to show a voice-input button in the UI.

    The callback receives a single argument, an object with these properties:

    - `mic` (Boolean) - whether mic access was granted
    - `speech` (Boolean) - whether the speech service responded (not blocked)
    - `reason` (String) - a short token describing the outcome: `"ok"`, `"denied"`, `"no-mic"`, `"speech-blocked"`, `"speech-unsupported"`, `"unsupported"`, or `"exception"`
    See Also:
      - `com.smartgwt.client.util.Browser#allowsSpeechRecognition`
      - `com.smartgwt.client.util.Browser#supportsSpeechRecognition`
      - `checkMicStatus()`

  - ### checkSpeechRecognition

    public static void checkSpeechRecognition(Function callback)
    See `checkSpeechRecognition()`

  - ### checkSpeechRecognition

    public static void checkSpeechRecognition(Function callback, Integer delay)
    Tests whether the browser's SpeechRecognition implementation can successfully contact the vendor-operated speech-to-text service it depends on, and updates `allowsSpeechRecognition`, `micAvailable`, and `micPermission` accordingly.

    This method is intrusive: it calls `getUserMedia({audio:true})`, which activates the microphone, shows browser recording-chrome, and may trigger a permissions dialog if the user has not already granted microphone access. It then starts a short throwaway SpeechRecognition session to detect browsers (such as Brave) that expose the API but block the underlying service.

    `VoiceAssist` calls this method on the user's first triple-tap to activate voice input. If the probe fails, VoiceAssist shows an explanatory message and does not enable. The result is cached, so subsequent triple-taps skip the probe. Developers may also call this method independently - for example, to decide whether to show a voice-input button in the UI.

    The callback receives a single argument, an object with these properties:

    - `mic` (Boolean) - whether mic access was granted
    - `speech` (Boolean) - whether the speech service responded (not blocked)
    - `reason` (String) - a short token describing the outcome: `"ok"`, `"denied"`, `"no-mic"`, `"speech-blocked"`, `"speech-unsupported"`, `"unsupported"`, or `"exception"`
    Parameters:
      `callback` - called when the check completes
      `delay` - milliseconds to wait for a "network" error before concluding the service is reachable; default 1000
    See Also:
      - `com.smartgwt.client.util.Browser#allowsSpeechRecognition`
      - `com.smartgwt.client.util.Browser#supportsSpeechRecognition`
      - `checkMicStatus()`

  - ### hasLocalStorage

    public static boolean hasLocalStorage()
    Returns whether localStorage is accessible in the current environment. This method performs a one-time check and caches the result. In CSP sandbox environments without 'allow-same-origin', localStorage access throws a SecurityError.
    Returns:
      true if localStorage is accessible, false otherwise

  - ### hasSessionStorage

    public static boolean hasSessionStorage()
    Returns whether sessionStorage is accessible in the current environment. This method performs a one-time check and caches the result. In CSP sandbox environments without 'allow-same-origin', sessionStorage access throws a SecurityError.
    Returns:
      true if sessionStorage is accessible, false otherwise

  - ### setIsDesktop

    public static void setIsDesktop(boolean isDesktop)
    Setter for `isDesktop` to allow this global variable to be changed at runtime. This advanced method is provided to override Smart GWT's detection of devices, since the framework can only detect devices that existed at the time the platform was released. Any changes to `isDesktop`, `isHandset`, or `isTablet` must be made before any component is created; it is an application error to attempt to change `isDesktop`, `isHandset`, or `isTablet` after components have been created.

    Note that setting `Browser.isDesktop` might affect the values of `isHandset` and `isTablet`.

    Parameters:
      `isDesktop` - new setting for `Browser.isDesktop`.

  - ### setIsHandset

    public static void setIsHandset(boolean isHandset)
    Setter for `isHandset` to allow this global variable to be changed at runtime. This advanced method is provided to override Smart GWT's detection of devices, since the framework can only detect devices that existed at the time the platform was released. Any changes to `isDesktop`, `isHandset`, or `isTablet` must be made before any component is created; it is an application error to attempt to change `isDesktop`, `isHandset`, or `isTablet` after components have been created.

    Note that setting `Browser.isHandset` might affect the values of `isDesktop` and `isTablet`.

    Parameters:
      `isHandset` - new setting for `Browser.isHandset`.

  - ### setIsMultiWindow

    public static void setIsMultiWindow(boolean isMultiWindow)
    Sets a non-default value for `isMultiWindow`, such as enabling it even if `OpenFin` isn't present.

    Note that this method may only be called from the `main window`, and only once.

    Parameters:
      `isMultiWindow` - new setting for `Browser.isMultiWindow`.

  - ### setIsTablet

    public static void setIsTablet(boolean isTablet)
    Setter for `isTablet` to allow this global variable to be changed at runtime. This advanced method is provided to override Smart GWT's detection of devices, since the framework can only detect devices that existed at the time the platform was released. Any changes to `isDesktop`, `isHandset`, or `isTablet` must be made before any component is created; it is an application error to attempt to change `isDesktop`, `isHandset`, or `isTablet` after components have been created.

    Note that setting `Browser.isTablet` might affect the values of `isDesktop` and `isHandset`.

    Parameters:
      `isTablet` - new setting for `Browser.isTablet`.

  - ### setIsTouch

    public static void setIsTouch(boolean isTouch)
    Setter for `isTouch` to allow this global variable to be changed at runtime. This advanced method is provided to override Smart GWT's auto-detection logic, since the framework can only detect touch devices that existed at the time the platform was released. Any change to `isTouch` must be made before any component is created; it is an application error to attempt to change `isTouch` after components have been created.

    Note that setting `Browser.isTouch` might affect the values of `isDesktop`, `isTablet`, and/or `isHandset`.

    Parameters:
      `isTouch` - new setting for `Browser.isTablet`.