Package org.htmlunit
Class BrowserVersion
- java.lang.Object
-
- org.htmlunit.BrowserVersion
-
- All Implemented Interfaces:
java.io.Serializable
public final class BrowserVersion extends java.lang.Object implements java.io.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 BrowserVersion[]
ALL_SUPPORTED_BROWSERS
Array with all supported browsers.static BrowserVersion
BEST_SUPPORTED
The best supported browser version at the moment.static BrowserVersion
CHROME
Latest Chrome.static BrowserVersion
EDGE
Latest Edge.static BrowserVersion
FIREFOX
Latest Firefox.static BrowserVersion
FIREFOX_ESR
Firefox ESR.static BrowserVersion
INTERNET_EXPLORER
Deprecated.as of version 3.0.0
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getAcceptEncodingHeader()
Returns the value used by the browser for theAccept_Encoding
header.java.lang.String
getAcceptLanguageHeader()
Returns the value used by the browser for theAccept_Language
header.java.lang.String
getApplicationCodeName()
Returns the application code name, for example "Mozilla".java.lang.String
getApplicationMinorVersion()
Returns the application minor version, for example "0".java.lang.String
getApplicationName()
Returns the application name, for example "Microsoft Internet Explorer".java.lang.String
getApplicationVersion()
Returns the application version, for example "4.0 (compatible; MSIE 6.0b; Windows 98)".java.lang.String
getBrowserLanguage()
Returns the browser application language, for example "en-us".java.util.Locale
getBrowserLocale()
Returns the browser locale.int
getBrowserVersionNumeric()
java.lang.String
getBuildId()
Returns the buildId.java.lang.String
getCpuClass()
Returns the type of CPU in the machine, for example "x86".java.lang.String
getCssAcceptHeader()
Returns the value used by the browser for theAccept
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(java.lang.String fontSize)
Returns the corresponding height of the specifiedfontSize
.java.lang.String[]
getHeaderNamesOrdered()
Gets the headers names, so they are sent in the given order (if included in the request).java.lang.String
getHtmlAcceptHeader()
Returns the value used by the browser for theAccept
header if requesting a page.java.lang.String
getImgAcceptHeader()
Returns the value used by the browser for theAccept
header if requesting an image.java.lang.String
getNickname()
Returns the short name of the browser likeFF
,IE
, etc.int
getPixesPerChar()
java.lang.String
getPlatform()
Returns the platform on which the application is running, for example "Win32".java.util.Set<PluginConfiguration>
getPlugins()
Returns the available plugins.java.lang.String
getProductSub()
Returns the productSub.java.lang.String
getScriptAcceptHeader()
Returns the value used by the browser for theAccept
header if requesting a script.java.lang.String
getSecClientHintUserAgentHeader()
Returns the value used by the browser for thesec-ch-ua
header.java.lang.String
getSecClientHintUserAgentPlatformHeader()
Returns the value used by the browser for thesec-ch-ua-platform
header.java.lang.String
getSystemLanguage()
Returns the system language, for example "en-us".java.util.TimeZone
getSystemTimezone()
Returns the systemTimeZone
.java.lang.String
getUploadMimeType(java.io.File file)
Determines the content type for the given file.java.lang.String
getUserAgent()
Returns the user agent string, for example "Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98)".java.lang.String
getUserLanguage()
Returns the user language, for example "en-us".java.lang.String
getVendor()
java.lang.String
getXmlHttpRequestAcceptHeader()
Returns the value used by the browser for theAccept
header if performing an XMLHttpRequest.boolean
hasFeature(BrowserVersionFeatures property)
Indicates if this instance has the given feature.boolean
isChrome()
Returnstrue
if thisBrowserVersion
instance represents some version of Google Chrome.boolean
isEdge()
Returnstrue
if thisBrowserVersion
instance represents some version of Microsoft Edge.boolean
isFirefox()
Returnstrue
if thisBrowserVersion
instance represents some version of Firefox.boolean
isFirefoxESR()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.boolean
isIE()
Returnstrue
if thisBrowserVersion
instance represents some version of Internet Explorer.boolean
isOnLine()
Returnstrue
if the browser is currently online.void
registerUploadMimeType(java.lang.String fileExtension, java.lang.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.java.lang.String
toString()
-
-
-
Field Detail
-
FIREFOX
public static final BrowserVersion FIREFOX
Latest Firefox.
-
FIREFOX_ESR
public static final BrowserVersion FIREFOX_ESR
Firefox ESR.
-
INTERNET_EXPLORER
@Deprecated public static final BrowserVersion INTERNET_EXPLORER
Deprecated.as of version 3.0.0Internet Explorer 11.
-
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 Detail
-
getDefault
public static BrowserVersion getDefault()
Returns the default browser version that is used whenever a specific version isn't specified. Defaults toBEST_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
-
isIE
public boolean isIE()
Returnstrue
if thisBrowserVersion
instance represents some version of Internet Explorer.- Returns:
- whether version is a version of IE
-
isChrome
public boolean isChrome()
Returnstrue
if thisBrowserVersion
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()
Returnstrue
if thisBrowserVersion
instance represents some version of Microsoft Edge.- Returns:
- whether this version is a version of a Chrome browser
-
isFirefox
public boolean isFirefox()
Returnstrue
if thisBrowserVersion
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 java.lang.String getNickname()
Returns the short name of the browser likeFF
,IE
, etc.- Returns:
- the short name (if any)
-
getBrowserVersionNumeric
public int getBrowserVersionNumeric()
- Returns:
- the browserVersionNumeric
-
getApplicationCodeName
public java.lang.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 java.lang.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 java.lang.String getApplicationName()
Returns the application name, for example "Microsoft Internet Explorer".- Returns:
- the application name
- See Also:
- MSDN documentation
-
getApplicationVersion
public java.lang.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 java.lang.String getVendor()
- Returns:
- the vendor
-
getBrowserLocale
public java.util.Locale getBrowserLocale()
Returns the browser locale. Default value isLANGUAGE_ENGLISH_US
if not explicitly configured.- Returns:
- the system locale
-
getBrowserLanguage
public java.lang.String getBrowserLanguage()
Returns the browser application language, for example "en-us". Default value isLANGUAGE_ENGLISH_US
if not explicitly configured.- Returns:
- the browser application language
- See Also:
- MSDN documentation
-
getCpuClass
public java.lang.String getCpuClass()
Returns the type of CPU in the machine, for example "x86". Default value isCPU_CLASS_X86
if not explicitly configured.- Returns:
- the type of CPU in the machine
- See Also:
- MSDN documentation
-
isOnLine
public boolean isOnLine()
Returnstrue
if the browser is currently online. Default value istrue
if not explicitly configured.- Returns:
true
if the browser is currently online- See Also:
- MSDN documentation
-
getPlatform
public java.lang.String getPlatform()
Returns the platform on which the application is running, for example "Win32". Default value isPLATFORM_WIN32
if not explicitly configured.- Returns:
- the platform on which the application is running
- See Also:
- MSDN documentation
-
getSystemLanguage
public java.lang.String getSystemLanguage()
Returns the system language, for example "en-us". Default value isLANGUAGE_ENGLISH_US
if not explicitly configured.- Returns:
- the system language
- See Also:
- MSDN documentation
-
getSystemTimezone
public java.util.TimeZone getSystemTimezone()
Returns the systemTimeZone
. Default value isAmerica/New_York
if not explicitly configured.- Returns:
- the system
TimeZone
-
getUserAgent
public java.lang.String getUserAgent()
Returns the user agent string, for example "Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98)".- Returns:
- the user agent string
-
getUserLanguage
public java.lang.String getUserLanguage()
Returns the user language, for example "en-us". Default value isLANGUAGE_ENGLISH_US
if not explicitly configured.- Returns:
- the user language
- See Also:
- MSDN documentation
-
getAcceptEncodingHeader
public java.lang.String getAcceptEncodingHeader()
Returns the value used by the browser for theAccept_Encoding
header.- Returns:
- the accept encoding header string
-
getAcceptLanguageHeader
public java.lang.String getAcceptLanguageHeader()
Returns the value used by the browser for theAccept_Language
header.- Returns:
- the accept language header string
-
getHtmlAcceptHeader
public java.lang.String getHtmlAcceptHeader()
Returns the value used by the browser for theAccept
header if requesting a page.- Returns:
- the accept header string
-
getScriptAcceptHeader
public java.lang.String getScriptAcceptHeader()
Returns the value used by the browser for theAccept
header if requesting a script.- Returns:
- the accept header string
-
getXmlHttpRequestAcceptHeader
public java.lang.String getXmlHttpRequestAcceptHeader()
Returns the value used by the browser for theAccept
header if performing an XMLHttpRequest.- Returns:
- the accept header string
-
getImgAcceptHeader
public java.lang.String getImgAcceptHeader()
Returns the value used by the browser for theAccept
header if requesting an image.- Returns:
- the accept header string
-
getCssAcceptHeader
public java.lang.String getCssAcceptHeader()
Returns the value used by the browser for theAccept
header if requesting a CSS declaration.- Returns:
- the accept header string
-
getSecClientHintUserAgentHeader
public java.lang.String getSecClientHintUserAgentHeader()
Returns the value used by the browser for thesec-ch-ua
header.- Returns:
- the sec-ch-ua header string
-
getSecClientHintUserAgentPlatformHeader
public java.lang.String getSecClientHintUserAgentPlatformHeader()
Returns the value used by the browser for thesec-ch-ua-platform
header.- Returns:
- the sec-ch-ua-platform header string
-
getPlugins
public java.util.Set<PluginConfiguration> getPlugins()
Returns the available plugins. This makes only sense for Firefox as only this browser makes this kind of information available via JavaScript.- Returns:
- the available plugins
-
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 java.lang.String getBuildId()
Returns the buildId.- Returns:
- the buildId
-
getProductSub
public java.lang.String getProductSub()
Returns the productSub.- Returns:
- the buildId
-
getHeaderNamesOrdered
public java.lang.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(java.lang.String fileExtension, java.lang.String mimeType)
Registers a new mime type for the provided file extension.- Parameters:
fileExtension
- the file extension used to determine the mime typemimeType
- the mime type to be used when uploading files with this extension
-
getUploadMimeType
public java.lang.String getUploadMimeType(java.io.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(java.lang.String fontSize)
Returns the corresponding height of the specifiedfontSize
.- Parameters:
fontSize
- the font size- Returns:
- the corresponding height
-
getPixesPerChar
public int getPixesPerChar()
- Returns:
- the pixesPerChar based on the specified
fontSize
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-