Package org.htmlunit
Class BrowserVersion
java.lang.Object
org.htmlunit.BrowserVersion
- All Implemented Interfaces:
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Because BrowserVersion is immutable we need a builder for this complex object setup. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BrowserVersion[]
Array with all supported browsers.static final BrowserVersion
The best supported browser version at the moment.static final BrowserVersion
Latest Chrome.static final BrowserVersion
Latest Edge.static final BrowserVersion
Latest Firefox.static final BrowserVersion
Firefox ESR. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value used by the browser for theAccept_Encoding
header.Returns the value used by the browser for theAccept_Language
header.Returns the application code name, for example "Mozilla".Returns the application minor version, for example "0".Returns the application name, for example "Netscape".Returns the application version, for example "4.0 (compatible; MSIE 6.0b; Windows 98)".Returns the browser application language, for example "en-us".Returns the browser locale.int
Returns the buildId.Returns the value used by the browser for theAccept
header if requesting a CSS declaration.static BrowserVersion
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 specifiedfontSize
.String[]
Gets the headers names, so they are sent in the given order (if included in the request).Returns the value used by the browser for theAccept
header if requesting a page.Returns the value used by the browser for theAccept
header if requesting an image.Returns the short name of the browser likeFF
,CHROME
, etc.int
Returns the platform on which the application is running, for example "Win32".Returns the productSub.Returns the value used by the browser for theAccept
header if requesting a script.Returns the value used by the browser for thesec-ch-ua
header.Returns the value used by the browser for thesec-ch-ua-platform
header.Returns the systemTimeZone
.getUploadMimeType
(File file) Determines the content type for the given file.Returns the user agent string, for example "Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98)".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
Returnstrue
if thisBrowserVersion
instance represents some version of Firefox.boolean
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.boolean
isOnLine()
Returnstrue
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.toString()
-
Field Details
-
FIREFOX
Latest Firefox. -
FIREFOX_ESR
Firefox ESR. -
EDGE
Latest Edge. -
CHROME
Latest Chrome. -
ALL_SUPPORTED_BROWSERS
Array with all supported browsers. -
BEST_SUPPORTED
The best supported browser version at the moment.
-
-
Method Details
-
isSameBrowser
- Parameters:
other
- theBrowserVersion
to compare with- Returns:
- true if the nickname and the numeric version are the same
-
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
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()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
Returns the short name of the browser likeFF
,CHROME
, etc.- Returns:
- the short name (if any)
-
getBrowserVersionNumeric
public int getBrowserVersionNumeric()- Returns:
- the browserVersionNumeric
-
getApplicationCodeName
Returns the application code name, for example "Mozilla". Default value is "Mozilla" if not explicitly configured.- Returns:
- the application code name
- See Also:
-
getApplicationMinorVersion
Returns the application minor version, for example "0". Default value is "0" if not explicitly configured.- Returns:
- the application minor version
- See Also:
-
getApplicationName
Returns the application name, for example "Netscape".- Returns:
- the application name
- See Also:
-
getApplicationVersion
Returns the application version, for example "4.0 (compatible; MSIE 6.0b; Windows 98)".- Returns:
- the application version
- See Also:
-
getVendor
- Returns:
- the vendor
-
getBrowserLocale
Returns the browser locale. Default value is ENGLISH_US if not explicitly configured.- Returns:
- the system locale
-
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:
-
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:
-
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:
-
getSystemTimezone
Returns the systemTimeZone
. Default value isAmerica/New_York
if not explicitly configured.- Returns:
- the system
TimeZone
-
getUserAgent
Returns the user agent string, for example "Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98)".- Returns:
- the user agent string
-
getAcceptEncodingHeader
Returns the value used by the browser for theAccept_Encoding
header.- Returns:
- the accept encoding header string
-
getAcceptLanguageHeader
Returns the value used by the browser for theAccept_Language
header.- Returns:
- the accept language header string
-
getHtmlAcceptHeader
Returns the value used by the browser for theAccept
header if requesting a page.- Returns:
- the accept header string
-
getScriptAcceptHeader
Returns the value used by the browser for theAccept
header if requesting a script.- Returns:
- the accept header string
-
getXmlHttpRequestAcceptHeader
Returns the value used by the browser for theAccept
header if performing an XMLHttpRequest.- Returns:
- the accept header string
-
getImgAcceptHeader
Returns the value used by the browser for theAccept
header if requesting an image.- Returns:
- the accept header string
-
getCssAcceptHeader
Returns the value used by the browser for theAccept
header if requesting a CSS declaration.- Returns:
- the accept header string
-
getSecClientHintUserAgentHeader
Returns the value used by the browser for thesec-ch-ua
header.- Returns:
- the sec-ch-ua header string
-
getSecClientHintUserAgentPlatformHeader
Returns the value used by the browser for thesec-ch-ua-platform
header.- Returns:
- the sec-ch-ua-platform header string
-
hasFeature
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
Returns the buildId.- Returns:
- the buildId
-
getProductSub
Returns the productSub.- Returns:
- the buildId
-
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
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
Determines the content type for the given file.- Parameters:
file
- the file- Returns:
- a content type or an empty string if unknown
-
getFontHeight
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
-