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.SerializableObjects 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 classBrowserVersion.BrowserVersionBuilderBecause BrowserVersion is immutable we need a builder for this complex object setup.
-
Field Summary
Fields Modifier and Type Field Description static BrowserVersion[]ALL_SUPPORTED_BROWSERSArray with all supported browsers.static BrowserVersionBEST_SUPPORTEDThe best supported browser version at the moment.static BrowserVersionCHROMELatest Chrome.static BrowserVersionEDGELatest Edge.static BrowserVersionFIREFOXLatest Firefox.static BrowserVersionFIREFOX_ESRFirefox ESR.static BrowserVersionINTERNET_EXPLORERDeprecated.as of version 3.0.0
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetAcceptEncodingHeader()Returns the value used by the browser for theAccept_Encodingheader.java.lang.StringgetAcceptLanguageHeader()Returns the value used by the browser for theAccept_Languageheader.java.lang.StringgetApplicationCodeName()Returns the application code name, for example "Mozilla".java.lang.StringgetApplicationMinorVersion()Returns the application minor version, for example "0".java.lang.StringgetApplicationName()Returns the application name, for example "Microsoft Internet Explorer".java.lang.StringgetApplicationVersion()Returns the application version, for example "4.0 (compatible; MSIE 6.0b; Windows 98)".java.lang.StringgetBrowserLanguage()Returns the browser application language, for example "en-us".java.util.LocalegetBrowserLocale()Returns the browser locale.intgetBrowserVersionNumeric()java.lang.StringgetBuildId()Returns the buildId.java.lang.StringgetCpuClass()Returns the type of CPU in the machine, for example "x86".java.lang.StringgetCssAcceptHeader()Returns the value used by the browser for theAcceptheader if requesting a CSS declaration.static BrowserVersiongetDefault()Returns the default browser version that is used whenever a specific version isn't specified.intgetFontHeight(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.StringgetHtmlAcceptHeader()Returns the value used by the browser for theAcceptheader if requesting a page.java.lang.StringgetImgAcceptHeader()Returns the value used by the browser for theAcceptheader if requesting an image.java.lang.StringgetNickname()Returns the short name of the browser likeFF,IE, etc.intgetPixesPerChar()java.lang.StringgetPlatform()Returns the platform on which the application is running, for example "Win32".java.util.Set<PluginConfiguration>getPlugins()Returns the available plugins.java.lang.StringgetProductSub()Returns the productSub.java.lang.StringgetScriptAcceptHeader()Returns the value used by the browser for theAcceptheader if requesting a script.java.lang.StringgetSecClientHintUserAgentHeader()Returns the value used by the browser for thesec-ch-uaheader.java.lang.StringgetSecClientHintUserAgentPlatformHeader()Returns the value used by the browser for thesec-ch-ua-platformheader.java.lang.StringgetSystemLanguage()Returns the system language, for example "en-us".java.util.TimeZonegetSystemTimezone()Returns the systemTimeZone.java.lang.StringgetUploadMimeType(java.io.File file)Determines the content type for the given file.java.lang.StringgetUserAgent()Returns the user agent string, for example "Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98)".java.lang.StringgetUserLanguage()Returns the user language, for example "en-us".java.lang.StringgetVendor()java.lang.StringgetXmlHttpRequestAcceptHeader()Returns the value used by the browser for theAcceptheader if performing an XMLHttpRequest.booleanhasFeature(BrowserVersionFeatures property)Indicates if this instance has the given feature.booleanisChrome()Returnstrueif thisBrowserVersioninstance represents some version of Google Chrome.booleanisEdge()Returnstrueif thisBrowserVersioninstance represents some version of Microsoft Edge.booleanisFirefox()Returnstrueif thisBrowserVersioninstance represents some version of Firefox.booleanisFirefoxESR()INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.booleanisIE()Returnstrueif thisBrowserVersioninstance represents some version of Internet Explorer.booleanisOnLine()Returnstrueif the browser is currently online.voidregisterUploadMimeType(java.lang.String fileExtension, java.lang.String mimeType)Registers a new mime type for the provided file extension.static voidsetDefault(BrowserVersion newBrowserVersion)Sets the default browser version that is used whenever a specific version isn't specified.java.lang.StringtoString()
-
-
-
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()
Returnstrueif thisBrowserVersioninstance represents some version of Internet Explorer.- Returns:
- whether version is a version of IE
-
isChrome
public boolean isChrome()
Returnstrueif thisBrowserVersioninstance 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()
Returnstrueif thisBrowserVersioninstance represents some version of Microsoft Edge.- Returns:
- whether this version is a version of a Chrome browser
-
isFirefox
public boolean isFirefox()
Returnstrueif thisBrowserVersioninstance 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_USif 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_USif 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_X86if not explicitly configured.- Returns:
- the type of CPU in the machine
- See Also:
- MSDN documentation
-
isOnLine
public boolean isOnLine()
Returnstrueif the browser is currently online. Default value istrueif not explicitly configured.- Returns:
trueif 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_WIN32if 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_USif not explicitly configured.- Returns:
- the system language
- See Also:
- MSDN documentation
-
getSystemTimezone
public java.util.TimeZone getSystemTimezone()
Returns the systemTimeZone. Default value isAmerica/New_Yorkif 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_USif 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_Encodingheader.- Returns:
- the accept encoding header string
-
getAcceptLanguageHeader
public java.lang.String getAcceptLanguageHeader()
Returns the value used by the browser for theAccept_Languageheader.- Returns:
- the accept language header string
-
getHtmlAcceptHeader
public java.lang.String getHtmlAcceptHeader()
Returns the value used by the browser for theAcceptheader if requesting a page.- Returns:
- the accept header string
-
getScriptAcceptHeader
public java.lang.String getScriptAcceptHeader()
Returns the value used by the browser for theAcceptheader if requesting a script.- Returns:
- the accept header string
-
getXmlHttpRequestAcceptHeader
public java.lang.String getXmlHttpRequestAcceptHeader()
Returns the value used by the browser for theAcceptheader if performing an XMLHttpRequest.- Returns:
- the accept header string
-
getImgAcceptHeader
public java.lang.String getImgAcceptHeader()
Returns the value used by the browser for theAcceptheader if requesting an image.- Returns:
- the accept header string
-
getCssAcceptHeader
public java.lang.String getCssAcceptHeader()
Returns the value used by the browser for theAcceptheader 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-uaheader.- Returns:
- the sec-ch-ua header string
-
getSecClientHintUserAgentPlatformHeader
public java.lang.String getSecClientHintUserAgentPlatformHeader()
Returns the value used by the browser for thesec-ch-ua-platformheader.- 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:
falseif 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:
toStringin classjava.lang.Object
-
-