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 private java.lang.StringacceptEncodingHeader_private java.lang.StringacceptLanguageHeader_static BrowserVersion[]ALL_SUPPORTED_BROWSERSArray with all supported browsers.private java.lang.StringapplicationCodeName_private java.lang.StringapplicationMinorVersion_private java.lang.StringapplicationName_private java.lang.StringapplicationVersion_static BrowserVersionBEST_SUPPORTEDThe best supported browser version at the moment.private java.util.LocalebrowserLocale_private intbrowserVersionNumeric_private java.lang.StringbuildId_static BrowserVersionCHROMELatest Chrome.private java.lang.StringcssAcceptHeader_private static BrowserVersionDefaultBrowserVersion_The default browser version.static BrowserVersionEDGELatest Edge.private java.util.Set<BrowserVersionFeatures>features_static BrowserVersionFIREFOXLatest Firefox.static BrowserVersionFIREFOX_ESRFirefox ESR.private static intFIREFOX_ESR_NUMERICprivate int[]fontHeights_private java.lang.String[]headerNamesOrdered_private java.lang.StringhtmlAcceptHeader_private java.lang.StringimgAcceptHeader_private static java.lang.StringLANGUAGE_ENGLISH_USUnited States English language identifier.private static java.lang.StringNETSCAPEApplication name the Netscape navigator series of browsers.private java.lang.Stringnickname_private booleanonLine_private java.lang.Stringplatform_private static java.lang.StringPLATFORM_WIN32The WIN32 platform.private java.util.Set<PluginConfiguration>plugins_private java.lang.StringproductSub_private java.lang.StringscriptAcceptHeader_private java.lang.StringsecClientHintUserAgentHeader_private java.lang.StringsecClientHintUserAgentPlatformHeader_private java.util.TimeZonesystemTimezone_private static java.lang.StringTIMEZONE_NEW_YORKUnited States.private java.util.Map<java.lang.String,java.lang.String>uploadMimeTypes_private java.lang.StringuserAgent_private java.lang.Stringvendor_private java.lang.StringxmlHttpRequestAcceptHeader_
-
Constructor Summary
Constructors Constructor Description BrowserVersion(int browserVersionNumeric, java.lang.String nickname)Creates a new browser version instance.
-
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 "Netscape".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.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,CHROME, 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.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.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.private voidinitFeatures()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.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
-
NETSCAPE
private static final java.lang.String NETSCAPE
Application name the Netscape navigator series of browsers.- See Also:
- Constant Field Values
-
LANGUAGE_ENGLISH_US
private static final java.lang.String LANGUAGE_ENGLISH_US
United States English language identifier.- See Also:
- Constant Field Values
-
TIMEZONE_NEW_YORK
private static final java.lang.String TIMEZONE_NEW_YORK
United States.- See Also:
- Constant Field Values
-
PLATFORM_WIN32
private static final java.lang.String PLATFORM_WIN32
The WIN32 platform.- See Also:
- Constant Field Values
-
FIREFOX
public static final BrowserVersion FIREFOX
Latest Firefox.
-
FIREFOX_ESR_NUMERIC
private static final int FIREFOX_ESR_NUMERIC
- See Also:
- Constant Field Values
-
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.
-
DefaultBrowserVersion_
private static BrowserVersion DefaultBrowserVersion_
The default browser version.
-
browserVersionNumeric_
private final int browserVersionNumeric_
-
nickname_
private final java.lang.String nickname_
-
applicationCodeName_
private java.lang.String applicationCodeName_
-
applicationMinorVersion_
private java.lang.String applicationMinorVersion_
-
applicationName_
private java.lang.String applicationName_
-
applicationVersion_
private java.lang.String applicationVersion_
-
buildId_
private java.lang.String buildId_
-
productSub_
private java.lang.String productSub_
-
vendor_
private java.lang.String vendor_
-
browserLocale_
private java.util.Locale browserLocale_
-
onLine_
private boolean onLine_
-
platform_
private java.lang.String platform_
-
systemTimezone_
private java.util.TimeZone systemTimezone_
-
userAgent_
private java.lang.String userAgent_
-
plugins_
private final java.util.Set<PluginConfiguration> plugins_
-
features_
private final java.util.Set<BrowserVersionFeatures> features_
-
acceptEncodingHeader_
private java.lang.String acceptEncodingHeader_
-
acceptLanguageHeader_
private java.lang.String acceptLanguageHeader_
-
htmlAcceptHeader_
private java.lang.String htmlAcceptHeader_
-
imgAcceptHeader_
private java.lang.String imgAcceptHeader_
-
cssAcceptHeader_
private java.lang.String cssAcceptHeader_
-
scriptAcceptHeader_
private java.lang.String scriptAcceptHeader_
-
secClientHintUserAgentHeader_
private java.lang.String secClientHintUserAgentHeader_
-
secClientHintUserAgentPlatformHeader_
private java.lang.String secClientHintUserAgentPlatformHeader_
-
xmlHttpRequestAcceptHeader_
private java.lang.String xmlHttpRequestAcceptHeader_
-
headerNamesOrdered_
private java.lang.String[] headerNamesOrdered_
-
fontHeights_
private int[] fontHeights_
-
uploadMimeTypes_
private final java.util.Map<java.lang.String,java.lang.String> uploadMimeTypes_
-
-
Constructor Detail
-
BrowserVersion
BrowserVersion(int browserVersionNumeric, java.lang.String nickname)Creates a new browser version instance.- Parameters:
browserVersionNumeric- the floating number version of the browsernickname- the short name of the browser (like "FF", "CHROME", ...) - has to be unique
-
-
Method Detail
-
initFeatures
private void initFeatures()
-
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
-
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,CHROME, 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 "Netscape".- 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
-
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
-
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
-
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
-
-