Package org.htmlunit

# Class BrowserVersion

java.lang.Object
org.htmlunit.BrowserVersion

All Implemented Interfaces:
  `Serializable`

public final class BrowserVersion extends Object implements Serializable
Objects of this class represent one specific version of a given browser. Predefined constants are provided for common browser versions.

You can create a different browser setup by using the BrowserVersionFactory.

             final String applicationName = "APPNAME";
             final String applicationVersion = "APPVERSION";
             final String userAgent = "USERAGENT";

             final BrowserVersion browser =
                     new BrowserVersion.BrowserVersionBuilder(BrowserVersion.FIREFOX)
                         .setApplicationName(applicationName)
                         .setApplicationVersion(applicationVersion)
                         .setUserAgent(userAgent)
                         .build();

But keep in mind this new one still behaves like an FF, only the stuff reported to the outside is changed. This is more or less the same you can do with real browsers installing plugins like UserAgentSwitcher.

See Also:
  - Serialized Form

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `BrowserVersion.BrowserVersionBuilder`
  Because BrowserVersion is immutable we need a builder for this complex object setup.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final BrowserVersion[]`
  `ALL_SUPPORTED_BROWSERS`
  Array with all supported browsers.
  `static final BrowserVersion`
  `BEST_SUPPORTED`
  The best supported browser version at the moment.
  `static final BrowserVersion`
  `CHROME`
  Latest Chrome.
  `static final BrowserVersion`
  `EDGE`
  Latest Edge.
  `static final BrowserVersion`
  `FIREFOX`
  Latest Firefox.
  `static final BrowserVersion`
  `FIREFOX_ESR`
  Firefox ESR.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `getAcceptEncodingHeader()`
  Returns the value used by the browser for the `Accept_Encoding` header.
  `String`
  `getAcceptLanguageHeader()`
  Returns the value used by the browser for the `Accept_Language` header.
  `String`
  `getApplicationCodeName()`
  Returns the application code name, for example "Mozilla".
  `String`
  `getApplicationMinorVersion()`
  Returns the application minor version, for example "0".
  `String`
  `getApplicationName()`
  Returns the application name, for example "Netscape".
  `String`
  `getApplicationVersion()`
  Returns the application version, for example "4.0 (compatible; MSIE 6.0b; Windows 98)".
  `String`
  `getBrowserLanguage()`
  Returns the browser application language, for example "en-us".
  `Locale`
  `getBrowserLocale()`
  Returns the browser locale.
  `int`
  `getBrowserVersionNumeric()`
  `String`
  `getBuildId()`
  Returns the buildId.
  `String`
  `getCssAcceptHeader()`
  Returns the value used by the browser for the `Accept` header if requesting a CSS declaration.
  `static BrowserVersion`
  `getDefault()`
  Returns the default browser version that is used whenever a specific version isn't specified.
  `int`
  `getFontHeight(String fontSize)`
  Returns the corresponding height of the specified `fontSize`.
  `String[]`
  `getHeaderNamesOrdered()`
  Gets the headers names, so they are sent in the given order (if included in the request).
  `String`
  `getHtmlAcceptHeader()`
  Returns the value used by the browser for the `Accept` header if requesting a page.
  `String`
  `getImgAcceptHeader()`
  Returns the value used by the browser for the `Accept` header if requesting an image.
  `String`
  `getNickname()`
  Returns the short name of the browser like `FF`, `CHROME`, etc.
  `int`
  `getPixesPerChar()`
  `String`
  `getPlatform()`
  Returns the platform on which the application is running, for example "Win32".
  `String`
  `getProductSub()`
  Returns the productSub.
  `String`
  `getScriptAcceptHeader()`
  Returns the value used by the browser for the `Accept` header if requesting a script.
  `String`
  `getSecClientHintUserAgentHeader()`
  Returns the value used by the browser for the `sec-ch-ua` header.
  `String`
  `getSecClientHintUserAgentPlatformHeader()`
  Returns the value used by the browser for the `sec-ch-ua-platform` header.
  `TimeZone`
  `getSystemTimezone()`
  Returns the system `TimeZone`.
  `String`
  `getUploadMimeType(File file)`
  Determines the content type for the given file.
  `String`
  `getUserAgent()`
  Returns the user agent string, for example "Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98)".
  `String`
  `getVendor()`
  `String`
  `getXmlHttpRequestAcceptHeader()`
  Returns the value used by the browser for the `Accept` header if performing an XMLHttpRequest.
  `boolean`
  `hasFeature(BrowserVersionFeatures property)`
  Indicates if this instance has the given feature.
  `boolean`
  `isChrome()`
  Returns `true` if this `BrowserVersion` instance represents some version of Google Chrome.
  `boolean`
  `isEdge()`
  Returns `true` if this `BrowserVersion` instance represents some version of Microsoft Edge.
  `boolean`
  `isFirefox()`
  Returns `true` if this `BrowserVersion` instance represents some version of Firefox.
  `boolean`
  `isFirefoxESR()`
  INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
  `boolean`
  `isOnLine()`
  Returns `true` if the browser is currently online.
  `boolean`
  `isSameBrowser(BrowserVersion other)`
  `void`
  `registerUploadMimeType(String fileExtension, String mimeType)`
  Registers a new mime type for the provided file extension.
  `static void`
  `setDefault(BrowserVersion newBrowserVersion)`
  Sets the default browser version that is used whenever a specific version isn't specified.
  `String`
  `toString()`

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

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

- ## Field Details

  - ### FIREFOX

    public static final BrowserVersion FIREFOX
    Latest Firefox.

  - ### FIREFOX_ESR

    public static final BrowserVersion FIREFOX_ESR
    Firefox ESR.

  - ### EDGE

    public static final BrowserVersion EDGE
    Latest Edge.

  - ### CHROME

    public static final BrowserVersion CHROME
    Latest Chrome.

  - ### ALL_SUPPORTED_BROWSERS

    public static final BrowserVersion[] ALL_SUPPORTED_BROWSERS
    Array with all supported browsers.

  - ### BEST_SUPPORTED

    public static final BrowserVersion BEST_SUPPORTED
    The best supported browser version at the moment.

- ## Method Details

  - ### isSameBrowser

    public boolean isSameBrowser(BrowserVersion other)
    Parameters:
      `other` - the `BrowserVersion` to compare with
    Returns:
      true if the nickname and the numeric version are the same

  - ### getDefault

    public static BrowserVersion getDefault()
    Returns the default browser version that is used whenever a specific version isn't specified. Defaults to `BEST_SUPPORTED`.
    Returns:
      the default browser version

  - ### setDefault

    public static void setDefault(BrowserVersion newBrowserVersion)
    Sets the default browser version that is used whenever a specific version isn't specified.
    Parameters:
      `newBrowserVersion` - the new default browser version

  - ### isChrome

    public boolean isChrome()
    Returns `true` if this `BrowserVersion` instance represents some version of Google Chrome. Note that Google Chrome does not return 'Chrome' in the application name, we have to look in the nickname.
    Returns:
      whether this version is a version of a Chrome browser

  - ### isEdge

    public boolean isEdge()
    Returns `true` if this `BrowserVersion` instance represents some version of Microsoft Edge.
    Returns:
      whether this version is a version of a Chrome browser

  - ### isFirefox

    public boolean isFirefox()
    Returns `true` if this `BrowserVersion` instance represents some version of Firefox.
    Returns:
      whether this version is a version of a Firefox browser

  - ### isFirefoxESR

    public boolean isFirefoxESR()
    INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
    Returns:
      whether this is version 78 of a Firefox browser

  - ### getNickname

    public String getNickname()
    Returns the short name of the browser like `FF`, `CHROME`, etc.
    Returns:
      the short name (if any)

  - ### getBrowserVersionNumeric

    public int getBrowserVersionNumeric()
    Returns:
      the browserVersionNumeric

  - ### getApplicationCodeName

    public String getApplicationCodeName()
    Returns the application code name, for example "Mozilla". Default value is "Mozilla" if not explicitly configured.
    Returns:
      the application code name
    See Also:
      - MSDN documentation

  - ### getApplicationMinorVersion

    public String getApplicationMinorVersion()
    Returns the application minor version, for example "0". Default value is "0" if not explicitly configured.
    Returns:
      the application minor version
    See Also:
      - MSDN documentation

  - ### getApplicationName

    public String getApplicationName()
    Returns the application name, for example "Netscape".
    Returns:
      the application name
    See Also:
      - MSDN documentation

  - ### getApplicationVersion

    public String getApplicationVersion()
    Returns the application version, for example "4.0 (compatible; MSIE 6.0b; Windows 98)".
    Returns:
      the application version
    See Also:
      - MSDN documentation

  - ### getVendor

    public String getVendor()
    Returns:
      the vendor

  - ### getBrowserLocale

    public Locale getBrowserLocale()
    Returns the browser locale. Default value is ENGLISH_US if not explicitly configured.
    Returns:
      the system locale

  - ### getBrowserLanguage

    public String getBrowserLanguage()
    Returns the browser application language, for example "en-us". Default value is ENGLISH_US if not explicitly configured.
    Returns:
      the browser application language
    See Also:
      - MSDN documentation

  - ### isOnLine

    public boolean isOnLine()
    Returns `true` if the browser is currently online. Default value is `true` if not explicitly configured.
    Returns:
      `true` if the browser is currently online
    See Also:
      - MSDN documentation

  - ### getPlatform

    public String getPlatform()
    Returns the platform on which the application is running, for example "Win32". Default value is 'Win32' if not explicitly configured.
    Returns:
      the platform on which the application is running
    See Also:
      - MSDN documentation

  - ### getSystemTimezone

    public TimeZone getSystemTimezone()
    Returns the system `TimeZone`. Default value is `America/New_York` if not explicitly configured.
    Returns:
      the system `TimeZone`

  - ### getUserAgent

    public String getUserAgent()
    Returns the user agent string, for example "Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98)".
    Returns:
      the user agent string

  - ### getAcceptEncodingHeader

    public String getAcceptEncodingHeader()
    Returns the value used by the browser for the `Accept_Encoding` header.
    Returns:
      the accept encoding header string

  - ### getAcceptLanguageHeader

    public String getAcceptLanguageHeader()
    Returns the value used by the browser for the `Accept_Language` header.
    Returns:
      the accept language header string

  - ### getHtmlAcceptHeader

    public String getHtmlAcceptHeader()
    Returns the value used by the browser for the `Accept` header if requesting a page.
    Returns:
      the accept header string

  - ### getScriptAcceptHeader

    public String getScriptAcceptHeader()
    Returns the value used by the browser for the `Accept` header if requesting a script.
    Returns:
      the accept header string

  - ### getXmlHttpRequestAcceptHeader

    public String getXmlHttpRequestAcceptHeader()
    Returns the value used by the browser for the `Accept` header if performing an XMLHttpRequest.
    Returns:
      the accept header string

  - ### getImgAcceptHeader

    public String getImgAcceptHeader()
    Returns the value used by the browser for the `Accept` header if requesting an image.
    Returns:
      the accept header string

  - ### getCssAcceptHeader

    public String getCssAcceptHeader()
    Returns the value used by the browser for the `Accept` header if requesting a CSS declaration.
    Returns:
      the accept header string

  - ### getSecClientHintUserAgentHeader

    public String getSecClientHintUserAgentHeader()
    Returns the value used by the browser for the `sec-ch-ua` header.
    Returns:
      the sec-ch-ua header string

  - ### getSecClientHintUserAgentPlatformHeader

    public String getSecClientHintUserAgentPlatformHeader()
    Returns the value used by the browser for the `sec-ch-ua-platform` header.
    Returns:
      the sec-ch-ua-platform header string

  - ### hasFeature

    public boolean hasFeature(BrowserVersionFeatures property)
    Indicates if this instance has the given feature. Used for HtmlUnit internal processing.
    Parameters:
      `property` - the property name
    Returns:
      `false` if this browser doesn't have this feature

  - ### getBuildId

    public String getBuildId()
    Returns the buildId.
    Returns:
      the buildId

  - ### getProductSub

    public String getProductSub()
    Returns the productSub.
    Returns:
      the buildId

  - ### getHeaderNamesOrdered

    public String[] getHeaderNamesOrdered()
    Gets the headers names, so they are sent in the given order (if included in the request).
    Returns:
      headerNames the header names in ordered manner

  - ### registerUploadMimeType

    public void registerUploadMimeType(String fileExtension, String mimeType)
    Registers a new mime type for the provided file extension.
    Parameters:
      `fileExtension` - the file extension used to determine the mime type
      `mimeType` - the mime type to be used when uploading files with this extension

  - ### getUploadMimeType

    public String getUploadMimeType(File file)
    Determines the content type for the given file.
    Parameters:
      `file` - the file
    Returns:
      a content type or an empty string if unknown

  - ### getFontHeight

    public int getFontHeight(String fontSize)
    Returns the corresponding height of the specified `fontSize`.
    Parameters:
      `fontSize` - the font size
    Returns:
      the corresponding height

  - ### getPixesPerChar

    public int getPixesPerChar()
    Returns:
      the pixesPerChar based on the specified `fontSize`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`