public class Browser
extends java.lang.Object
Browser allows displaying modern HTML5/CSS3/JavaScript web pages, PDF documents, PPAPI Flash content if appropriate PPAPI Chromium plugin is installed.
Each Browser instance is running in separate native process and communicates with Java process via Inter-Process-Communication (IPC) bridge. If Browser instance is disposed unexpectedly in native process (e.g. due to crash in Flash plugin), it will not affect Java application. The application will continue working. When you don't need to use Browser instance you must dispose it using thedispose()
method to free allocated memory and resources. Once you dispose Browser instance, you cannot use it anymore, so if you call its method after you dispose Browser instance, you will get
IllegalStateException
error.
By default Browser instance displays popup windows, JavaScript dialogs such as alert, confirm, prompt, file open/save dialogs, print settings dialog, etc. To modify default behavior feel free to register your own implementation of corresponding handlers.
Modifier and Type | Field and Description |
---|---|
static int |
FOCUSED_FRAME_ID
The focused frame id constant.
聚焦帧ID常数。 |
static int |
MAIN_FRAME_ID
The main frame id constant.
主框架ID常数。 |
Constructor and Description |
---|
Browser()
Creates a new
Browser instance with default
BrowserContext and
BrowserType.HEAVYWEIGHT type.
|
Browser(BrowserContext browserContext)
Creates a new
Browser instance with specified
BrowserContext .
|
Browser(BrowserType browserType)
|
Browser(BrowserType browserType, BrowserContext browserContext)
|
Modifier and Type | Method and Description |
---|---|
void |
addConsoleListener(ConsoleListener listener)
Adds the specified console listener to receive console change events from this browser instance.
添加指定的控制台侦听器以从此浏览器实例接收控制台更改事件。 |
void |
addDisposeListener(DisposeListener<Browser> listener)
Adds the specified dispose listener to receive browser dispose events from this browser instance.
添加指定的Dispose侦听器,以接收来自此浏览器实例的浏览器Dispose事件。 |
void |
addLoadListener(LoadListener listener)
Adds the specified load listener to receive browser load events from this browser instance.
添加指定的负载侦听器以从该浏览器实例接收浏览器负载事件。 |
void |
addRenderListener(RenderListener listener)
Adds the specified render listener to receive render events from this browser instance.
添加指定的渲染侦听器,以从该浏览器实例接收渲染事件。 |
void |
addScriptContextListener(ScriptContextListener listener)
Adds the given script context
添加给定的脚本上下文侦听器以从此浏览器实例接收脚本上下文事件。 listener to receive script context events from this browser instance.
|
void |
addStatusListener(StatusListener listener)
Adds the specified status listener to receive browser status change events from this browser instance.
添加指定的状态侦听器以从该浏览器实例接收浏览器状态更改事件。 |
void |
addTitleListener(TitleListener listener)
Adds the specified title listener to receive browser title change events from this browser instance.
添加指定的标题侦听器,以从该浏览器实例接收浏览器标题更改事件。 |
void |
addUploadProgressListener(UploadProgressListener listener)
Adds the specified upload progress listener to receive upload progress events from this browser instance.
添加指定的上传进度侦听器,以从该浏览器实例接收上传进度事件。 |
boolean |
addWordToSpellCheckerDictionary(java.lang.String word)
Adds a new word to current user's spellchecker dictionary and returns boolean value that indicates whether word has been added to the dictionary successfully or not.
向当前用户的拼写检查器词典中添加一个新单词,并返回布尔值,该值指示单词是否已成功添加到词典中。 |
boolean |
canGoBack()
Indicates whether browser can navigate back.
指示浏览器是否可以向后导航。 |
boolean |
canGoForward()
Indicates whether browser can navigate forward.
指示浏览器是否可以向前导航。 |
boolean |
canGoToOffset(int offset)
Indicates whether browser can navigate to the specified offset from the "current navigation entry" in the back/forward list of the current Browser instance.
指示浏览器是否可以从当前浏览器实例的后退/前进列表中的“当前导航条目”导航到指定的偏移量。 |
void |
dispose()
Disposes the current Browser instance and waits until all pending Browser tasks are completed.
处置当前的浏览器实例,并等待所有未完成的浏览器任务完成。 |
boolean |
dispose(boolean checkBeforeUnload)
Tries to unload current document and if unload is not declined, disposes current Browser instance and waits until all pending Browser tasks are completed.
尝试卸载当前文档,如果没有拒绝卸载,请处置当前的Browser实例,并等待所有未完成的Browser任务完成。 |
boolean |
executeCommand(EditorCommand command)
Executes the
在加载的网页上当前聚焦的框架中执行命令。 command in the currently focused frame on the loaded web page.
|
boolean |
executeCommand(EditorCommand command, java.lang.String value)
Executes the
在加载的网页上的焦点框中执行带有命令值的命令。 command with command
value in the focused frame on the loaded web page.
|
boolean |
executeCommand(long frameId, EditorCommand command)
Executes the
在frameId指定的框架中执行命令。 command in the frame, specified by
frameId .
|
boolean |
executeCommand(long frameId, EditorCommand command, java.lang.String value)
Executes the
在frameId指定的帧中以命令值执行命令。 command with command
value in the frame specified by
frameId .
|
void |
executeJavaScript(long frameId, java.lang.String javaScript)
Executes
在由frameId标识的Web框架的上下文中执行javaScript。 javaScript in the context of the web frame identified by
frameId .
|
void |
executeJavaScript(java.lang.String javaScript)
Executes
在当前页面的上下文中执行javaScript。 javaScript in the context of the current page.
|
JSValue |
executeJavaScriptAndReturnValue(long frameId, java.lang.String javaScript)
Executes
在frameId所标识的Web框架的上下文中执行javaScript,并将JavaScript执行的结果作为JSValue对象返回。 javaScript in the context of the web frame identified by
frameId and returns the result of JavaScript execution as
JSValue object.
|
JSValue |
executeJavaScriptAndReturnValue(java.lang.String javaScript)
Executes
在当前页面的上下文中执行javaScript并将JavaScript执行的结果作为JSValue对象返回。 javaScript in the context of the current page and returns the result of JavaScript execution as
JSValue object.
|
SearchResult |
findText(SearchParams params)
Deprecated.
已过时。考虑使用非阻塞的findText(SearchParams,SearchResultCallback)方法
Consider using the non-blocking
findText(SearchParams, SearchResultCallback) method
|
void |
findText(SearchParams params, SearchResultCallback callback)
Finds specified text, highlights all matches and selects the first match on the currently loaded web page.
查找指定的文本,突出显示所有匹配项,然后选择当前加载的网页上的第一个匹配项。 |
void |
forwardKeyEvent(BrowserKeyEvent event)
Forwards the given keyboard
将给定的键盘事件转发到加载的网页上当前聚焦的HTML元素。 event to currently focused HTML element on the loaded web page.
|
void |
forwardMouseEvent(BrowserMouseEvent event)
Forwards the given mouse
将给定的鼠标事件转发到加载的网页。 event to the loaded web page.
|
java.lang.String |
getAcceptLanguage()
Deprecated.
已过时。使用BrowserContext.getAcceptLanguage()代替。
use
BrowserContext.getAcceptLanguage() instead.
|
CacheStorage |
getCacheStorage()
Provides access to the cache storage associated with this Browser instance.
提供对与此浏览器实例关联的缓存存储的访问。 |
java.util.List<ConsoleListener> |
getConsoleListeners()
Returns a list of all the console listeners registered on this browser.
返回在此浏览器上注册的所有控制台侦听器的列表。 |
BrowserContext |
getContext()
Returns
返回与此浏览器实例关联的BrowserContext。 BrowserContext associated with this browser instance.
|
ContextMenuHandler |
getContextMenuHandler()
Returns the registered context menu handler or
返回已注册的上下文菜单处理程序;如果当前未注册任何上下文菜单处理程序,则返回null。 null if no context menu handler is currently registered.
|
CookieStorage |
getCookieStorage()
Provides access to the cookie storage.
提供对cookie存储的访问。 |
NavigationEntry |
getCurrentNavigationEntry()
Returns the current navigation entry in the back/forward list of the current Browser instance.
返回当前浏览器实例的后退/前进列表中的当前导航条目。 |
int |
getCurrentNavigationEntryIndex()
Returns the index of the current navigation entry in the back/forward list of the current Browser instance.
返回当前浏览器实例的后退/前进列表中当前导航条目的索引。 |
java.lang.String |
getCustomStyleSheet()
Returns a string that represents a custom style sheet provided via the
返回一个字符串,该字符串表示通过setCustomStyleSheet(String)方法提供的自定义样式表。 setCustomStyleSheet(String) method.
|
DialogHandler |
getDialogHandler()
Returns registered JavaScript dialog handler or
返回已注册的JavaScript对话框处理程序;如果当前未注册任何对话框处理程序,则返回null。 null if no dialog handler is currently registered.
|
java.util.List<DisposeListener<Browser>> |
getDisposeListeners()
Returns a list of all the browser dispose listeners registered on this browser.
返回在此浏览器上注册的所有浏览器处理侦听器的列表。 |
DOMDocument |
getDocument()
Returns HTML document of the main frame of the currently loaded web page or
返回当前加载的网页的主框架的HTML文档;如果该网页未加载或不可用,则返回null。 null if the web page is not loaded or not available (e.g.
|
DOMDocument |
getDocument(long frameId)
Returns HTML document of the specified frame on the currently loaded web page or
返回当前加载的网页上指定框架的HTML文档;如果该网页未加载或不可用,则返回null。 null if the web page is not loaded or not available (e.g.
|
DownloadHandler |
getDownloadHandler()
Returns registered file download handler or
返回注册的文件下载处理程序;如果当前未注册任何文件下载处理程序,则返回null。 null if no file download handler is currently registered.
|
java.util.List<java.lang.Long> |
getFramesIds()
Returns a list of child frames IDs of the currently loaded document.
返回当前加载文档的子框架ID列表。 |
java.util.List<java.lang.Long> |
getFramesIds(long frameId)
Returns a list of child frames IDs for the given frame with
返回带有frameId的给定框架的子框架ID列表。 frameId .
|
FullScreenHandler |
getFullScreenHandler()
Returns current full-screen handler or
返回当前的全屏处理程序;如果没有注册的处理程序,则返回null。 null when there's no registered handlers.
|
java.lang.String |
getHTML()
Returns HTML of the currently loaded web page or empty string if the web page is still loading and its HTML is not available yet.
返回当前加载的网页的HTML;如果该网页仍在加载且其HTML尚不可用,则返回空字符串。 |
java.lang.String |
getHTML(long frameId)
Returns HTML of a specified web frame on the currently loaded web page.
返回当前加载的网页上指定Web框架的HTML。 |
JSContext |
getJSContext()
Returns JavaScript context of the main frame on the currently loaded web page.
返回当前加载的网页上主框架的JavaScript上下文。 |
JSContext |
getJSContext(long frameId)
Returns JavaScript context of a specified
返回当前加载的网页上指定frameId的JavaScript上下文。 frameId on the currently loaded web page.
|
LoadHandler |
getLoadHandler()
Returns registered load handler or
返回已注册的加载处理程序;如果当前未注册任何加载处理程序,则返回null。 null if no load handler is currently registered.
|
java.util.List<LoadListener> |
getLoadListeners()
Returns a list of all the load listeners registered on this browser.
返回在此浏览器上注册的所有负载侦听器的列表。 |
WebStorage |
getLocalWebStorage()
Returns Local Web Storage associated with main frame.
返回与主机关联的本地Web存储。 |
WebStorage |
getLocalWebStorage(long frameId)
Returns Local Web Storage associated with specified frame or
返回与指定框架关联的本地Web存储或为null。 null .
|
MediaStreamDeviceManager |
getMediaStreamDeviceManager()
Provides access to media device manager of the current Browser instance.
提供对当前浏览器实例的媒体设备管理器的访问。 |
NavigationEntry |
getNavigationEntryAtIndex(int index)
Returns the navigation entry at the specified
返回当前浏览器实例的后退/前进列表中指定索引处的导航条目。 index in the back/forward list of the current Browser instance.
|
NavigationEntry |
getNavigationEntryAtOffset(int offset)
Returns the navigation entry at the specified
返回当前浏览器实例的后退/前进列表中与当前位置偏移指定偏移量的导航条目。 offset from current in the back/forward list of the current Browser instance.
|
int |
getNavigationEntryCount()
Returns the number of navigation entries in the back/forward list of the current Browser instance.
返回当前浏览器实例的后退/前进列表中的导航条目数。 |
DOMNodeAtPoint |
getNodeAtPoint(int x, int y)
Returns information about HTML Node at the location specified by the
在加载的网页的坐标空间处,由x和y参数指定的位置返回有关HTML节点的信息。 x and
y parameters at the coordinate space of the loaded web page.
|
DOMNodeAtPoint |
getNodeAtPoint(java.awt.Point point)
Returns information about HTML Node at the location specified by the
在加载的网页的坐标空间中,由point参数指定的位置返回有关HTML Node的信息。 point parameter at the coordinate space of the loaded web page.
|
PermissionHandler |
getPermissionHandler()
Returns registered permission handler or
返回已注册的权限处理程序;如果当前未注册任何权限处理程序,则返回null。 null if no permission handler is current registered.
|
PluginManager |
getPluginManager()
Provides access to plugin manager of the current Browser instance.
提供对当前浏览器实例的插件管理器的访问。 |
PopupHandler |
getPopupHandler()
Returns the active popup handler.
返回活动的弹出处理程序。 |
BrowserPreferences |
getPreferences()
Returns current Browser's preferences.
返回当前浏览器的首选项。 |
PrintHandler |
getPrintHandler()
Returns current print handler or
返回当前的打印处理程序;如果没有安装的处理程序,则返回null。 null when there's no installed handler.
|
java.lang.String |
getRemoteDebuggingURL()
Returns a string that represents URL of the Chrome Developers Tools web page, that allows you to debug the loaded web page in the current Browser instance.
返回一个字符串,该字符串代表Chrome开发人员工具网页的URL,该字符串可让您在当前的Browser实例中调试已加载的网页。 |
java.util.List<RenderListener> |
getRenderListeners()
Returns a list of all the render listeners registered on this browser.
返回在此浏览器上注册的所有渲染侦听器的列表。 |
RenderProcessInfo |
getRenderProcessInfo()
Returns information about Chromium render process associated with the current Browser instance.
返回有关与当前Browser实例关联的Chromium渲染过程的信息。 |
java.util.List<ScriptContextListener> |
getScriptContextListeners()
Returns a list of all the script context listeners registered on this browser.
返回在此浏览器上注册的所有脚本上下文侦听器的列表。 |
java.lang.String |
getSelectedHTML()
Returns selected HTML in the currently focused frame or empty string if there is no selection.
返回当前焦点框架中的选定HTML;如果没有选择,则返回空字符串。 |
java.lang.String |
getSelectedHTML(long frameId)
Returns selected HTML for the frame, specified by
返回为框架选择的HTML,由frameId指定;如果没有选择,则返回空字符串。 frameId or empty string if there is no selection.
|
java.lang.String |
getSelectedText()
Returns selected text in the currently focused frame or empty string if there is no selection.
返回当前焦点框架中的选定文本,如果没有选择,则返回空字符串。 |
java.lang.String |
getSelectedText(long frameId)
Returns selected text for the frame, specified by
返回框架的选定文本,由frameId指定;如果没有选择,则返回空字符串。 frameId or empty string if there is no selection.
|
WebStorage |
getSessionWebStorage()
Returns Session Web Storage associated with main frame.
返回与主机关联的会话Web存储。 |
WebStorage |
getSessionWebStorage(long frameId)
Returns Session Web Storage associated with specified frame or
返回与指定框架或null关联的会话Web存储。 null .
|
java.util.List<StatusListener> |
getStatusListeners()
Returns a list of all the browser status listeners registered on this browser.
返回在此浏览器上注册的所有浏览器状态侦听器的列表。 |
java.lang.String |
getTitle()
Returns the string that represents a title of the currently loaded web page.
返回表示当前加载的网页标题的字符串。 |
java.util.List<TitleListener> |
getTitleListeners()
Returns a list of all the browser title listeners registered on this browser.
返回在此浏览器上注册的所有浏览器标题侦听器的列表。 |
BrowserType |
getType()
Returns the browser type of the current instance.
返回当前实例的浏览器类型。 |
java.util.List<UploadProgressListener> |
getUploadProgressListeners()
Returns a list of all the upload progress listeners registered on this browser.
返回在此浏览器上注册的所有上传进度侦听器的列表。 |
java.lang.String |
getURL()
Returns URL of the currently loaded web page.
返回当前加载网页的URL。 |
java.lang.String |
getUserAgent()
Returns the user agent string for current Browser instance.
返回当前浏览器实例的用户代理字符串。 |
double |
getZoomLevel()
Returns zoom level for the currently loaded web page.
返回当前加载的网页的缩放级别。 |
void |
goBack()
Navigates browser back or does nothing if it cannot navigate back.
向后浏览浏览器,或者如果无法向后浏览,则不执行任何操作。 |
void |
goForward()
Navigates browser forward or does nothing if it cannot navigate forward.
向前浏览浏览器;如果无法向前浏览,则不执行任何操作。 |
void |
goToIndex(int index)
Navigates to the specified absolute index in the back/forward list of the current Browser instance.
导航到当前浏览器实例的后退/前进列表中的指定绝对索引。 |
void |
goToOffset(int offset)
Navigates to the specified offset from the "current navigation entry".
导航到“当前导航条目”的指定偏移量。 |
static void |
invokeAndWaitFinishLoadingMainFrame(Browser browser, Callback<Browser> task)
Blocks current thread execution, invokes the given
阻止当前线程执行,调用必须启动网页加载的给定任务,并等待直到网页的主框架完全加载或达到超时为止。 task that must initiate web page loading, and waits until the main frame of the web page is loaded completely or until the timeout is reached.
|
static void |
invokeAndWaitFinishLoadingMainFrame(Browser browser, Callback<Browser> task, int timeoutInSeconds)
Blocks current thread execution, invokes the given
阻止当前线程执行,调用必须启动网页加载的给定任务,并等待直到网页的主框架完全加载或达到给定的timeoutInSeconds。 task that must initiate web page loading, and waits until the main frame of the web page is loaded completely or until the given
timeoutInSeconds is reached.
|
boolean |
isAudioMuted()
Returns
当此浏览器实例的音频输出被静音时,返回true。 true when audio output for this Browser instance is muted.
|
boolean |
isAudioPlaying()
Returns
当前在加载的网页上正在播放音频时,返回true。 true when the audio is currently playing on the loaded web page.
|
boolean |
isCommandEnabled(EditorCommand command)
Returns
如果可以在加载的网页上当前聚焦的框架中执行命令,则返回true。 true if the
command can be executed in the currently focused frame on the loaded web page.
|
boolean |
isDisposed()
Returns
处置当前浏览器实例时,返回true。 true when the current browser instance is disposed.
|
boolean |
isLoading()
Returns
当浏览器正在加载资源时,返回true。 true when browser is loading resource.
|
boolean |
isSandboxEnabled()
Returns true if sandbox enabled for render process.
如果为渲染过程启用了沙箱,则返回true。 |
boolean |
isZoomEnabled()
Indicates whether zoom functionality is enabled for this browser instance or not.
指示是否为此浏览器实例启用了缩放功能。 |
void |
loadData(LoadDataParams params)
Loads the given
将具有指定mime类型和可选文本编码的给定LoadDataParams.getData()字符串加载到当前加载的文档的主框架中。 LoadDataParams.getData() string with specified mime type and optional text encoding into the main frame on the currently loaded document.
|
void |
loadData(long frameId, LoadDataParams params)
Loads the given
将具有指定的mime类型和可选文本编码的给定LoadDataParams.getData()字符串加载到当前加载的文档的指定框架中。 LoadDataParams.getData() string with specified mime type and optional text encoding into the specified frame on the currently loaded document.
|
void |
loadHTML(LoadHTMLParams params)
Loads the given
将给定的LoadHTMLParams.getHTML()内容加载到当前加载的文档的主框架中。 LoadHTMLParams.getHTML() content into the main frame of the currently loaded document.
|
void |
loadHTML(long frameId, LoadHTMLParams params)
Loads the given
将给定的LoadHTMLParams.getHTML()内容加载到当前加载文档的指定框架中。 LoadHTMLParams.getHTML() content into the specified frame of the currently loaded document.
|
void |
loadHTML(long frameId, java.lang.String html)
Loads the given
将给定的html内容加载到当前加载文档的指定框架中。 html content into the specified frame of the currently loaded document.
|
void |
loadHTML(java.lang.String html)
Updates content of the browser instance with the
使用html字符串更新浏览器实例的内容。 html string.
|
void |
loadURL(LoadURLParams params)
Navigates to a resource identified by a
导航到由LoadURLParams.getURL()标识的资源。 LoadURLParams.getURL() .
|
void |
loadURL(long frameId, java.lang.String url)
Navigates a web frame with
将当前加载的网页上带有frameId的网络框架导航到该URL标识的资源。 frameId on the currently loaded web page to a resource identified by the
url .
|
void |
loadURL(java.lang.String url)
Navigates to a resource identified by a URL.
导航到URL标识的资源。 |
void |
print()
Prints main frame of the currently loaded web page.
打印当前加载的网页的主框架。 |
void |
print(long frameId)
Prints frame with the given
在当前加载的网页上打印具有给定frameId的框架。 frameId on the currently loaded web page.
|
void |
reload()
Equivalent of
等效于reload(false)。 reload(false) .
|
void |
reload(boolean checkForRepost)
Reloads the currently loaded web page.
重新加载当前加载的网页。 |
void |
reloadIgnoringCache()
Equivalent of
等效于reloadIgnoringCache(false)。 reloadIgnoringCache(false) .
|
void |
reloadIgnoringCache(boolean checkForRepost)
Reloads the currently loaded web page ignoring caches.
重新加载当前加载的网页,忽略缓存。 |
void |
removeConsoleListener(ConsoleListener listener)
Removes the specified console listener so that it no longer receives browser console events from this browser instance.
删除指定的控制台侦听器,以使其不再从该浏览器实例接收浏览器控制台事件。 |
void |
removeDisposeListener(DisposeListener<Browser> listener)
Removes the specified dispose listener so that it no longer receives browser dispose events from this browser instance.
移除指定的Dispose侦听器,使其不再从该浏览器实例接收浏览器Dispose事件。 |
void |
removeLoadListener(LoadListener listener)
Removes the specified load listener so that it no longer receives browser load events from this browser instance.
删除指定的负载侦听器,使其不再从该浏览器实例接收浏览器负载事件。 |
boolean |
removeNavigationEntryAtIndex(int index)
Removes navigation entry at the specified
删除当前浏览器实例的后退/前进列表中指定索引处的导航条目。 index in the back/forward list of the current Browser instance.
|
void |
removeRenderListener(RenderListener listener)
Removes the specified render listener so that it no longer receives browser render events from this browser instance.
移除指定的渲染侦听器,使其不再从该浏览器实例接收浏览器渲染事件。 |
void |
removeScriptContextListener(ScriptContextListener listener)
Removes the given script context listener so that it no longer receives script context events from this browser instance.
删除给定的脚本上下文侦听器,以使其不再从该浏览器实例接收脚本上下文事件。 |
void |
removeStatusListener(StatusListener listener)
Removes the specified status listener so that it no longer receives browser status events from this browser instance.
删除指定的状态侦听器,以使其不再从该浏览器实例接收浏览器状态事件。 |
void |
removeTitleListener(TitleListener listener)
Removes the specified title listener so that it no longer receives browser title events from this browser instance.
删除指定的标题侦听器,以使其不再从该浏览器实例接收浏览器标题事件。 |
void |
removeUploadProgressListener(UploadProgressListener listener)
Removes the specified upload progress listener so that it no longer receives browser upload progress from this browser instance.
删除指定的上载进度侦听器,以使其不再从该浏览器实例接收浏览器上载进度。 |
void |
replaceMisspelledWord(java.lang.String word)
Replaces misspelled word under cursor on the currently loaded web page with the given
用给定的单词替换当前加载网页上光标下方的拼写错误的单词。 word .
|
boolean |
saveWebPage(java.lang.String filePath, java.lang.String dirPath, SavePageType saveType)
Saves the current web page as a file or set of files.
保存当前网页作为一个文件或文件集。 |
void |
setAcceptLanguage(java.lang.String acceptLanguage)
Deprecated.
已过时。 acceptLanguage参数不支持RFC 7231标准。改用BrowserContext.setAcceptLanguage(String)。
the
acceptLanguage parameter doesn't support the RFC 7231 Standard. Use BrowserContext.setAcceptLanguage(String) instead.
|
void |
setAudioMuted(boolean muted)
Mutes all audio output for this Browser instance.
将此浏览器实例的所有音频输出静音。 |
void |
setContextMenuHandler(ContextMenuHandler handler)
Sets handler for context menu requests that will be invoked every time the user clicks right mouse button.
设置上下文菜单请求的处理程序,该请求将在用户每次单击鼠标右键时调用。 |
void |
setCustomStyleSheet(java.lang.String customStyleSheet)
Injects the given
将表示自定义样式表(CSS)的给定customStyleSheet字符串插入此实例中加载的每个HTML文档中。 customStyleSheet string that represents a custom style sheet (CSS) into every HTML document loaded in this instance.
|
void |
setDialogHandler(DialogHandler handler)
Sets the dialog handler that will be used to handle JavaScript dialogs such as alert, confirmation and prompt.
设置将用于处理JavaScript对话框(例如警报,确认和提示)的对话框处理程序。 |
void |
setDownloadHandler(DownloadHandler handler)
Sets the file download handler that will be invoked every time the Browser downloads a file.
设置每次浏览器下载文件时将调用的文件下载处理程序。 |
void |
setFullScreenHandler(FullScreenHandler handler)
Sets a new full-screen handler to receive notifications when HTML element on the web page goes into a full-screen mode.
设置新的全屏处理程序,以在网页上的HTML元素进入全屏模式时接收通知。 |
void |
setLoadHandler(LoadHandler handler)
Sets the load handler that will be invoked every time when Browser loads a web page.
设置每次浏览器加载网页时将调用的加载处理程序。 |
void |
setPermissionHandler(PermissionHandler handler)
Sets permission handler that will be invoked every time the engine asks about permission for different functionality such as geolocation, desktop notifications, etc.
设置权限处理程序,每当引擎询问有关不同功能(例如地理位置,桌面通知等)的权限时,将调用该权限处理程序。 |
void |
setPopupHandler(PopupHandler handle)
Sets a new popup handle that will be used to handle popup windows.
设置一个新的弹出句柄,将用于处理弹出窗口。 |
void |
setPreferences(BrowserPreferences preferences)
Updates Browser's preferences.
更新浏览器的首选项。 |
void |
setPrintHandler(PrintHandler handler)
Sets a print handler that will be invoked every time when printing requests for print settings.
设置一个打印处理程序,该打印处理程序在每次打印请求打印设置时都会被调用。 |
void |
setSize(int width, int height)
Updates size of the current Browser's view.
更新当前浏览器视图的大小。 |
void |
setUserAgent(java.lang.String userAgent)
Configures the user agent string for current Browser instance.
为当前浏览器实例配置用户代理字符串。 |
void |
setZoomEnabled(boolean enabled)
Modifies the way how zoom changes are handled.
修改缩放更改的处理方式。 |
void |
setZoomLevel(double zoomLevel)
Updates zoom level for the currently loaded web page.
更新当前加载的网页的缩放级别。 |
void |
stop()
Cancels any pending navigation or download operation and stops any dynamic page elements, such as background sounds and animations.
取消任何待处理的导航或下载操作,并停止任何动态页面元素,例如背景声音和动画。 |
void |
stopFindingText(StopFindAction action)
Stops finding text and resets found matches highlighting.
停止查找文本并重置找到的匹配突出显示。 |
void |
zoomIn()
Updates zoom level for the currently loaded web page on one step up.
一步更新当前加载的网页的缩放级别。 |
void |
zoomOut()
Updates zoom level for the currently loaded web page on one step down.
向下一级更新当前加载网页的缩放级别。 |
void |
zoomReset()
Resents zoom level for the currently loaded web page to default value.
将当前加载的网页的缩放级别重新设置为默认值。 |
public static final int MAIN_FRAME_ID
frameId
parameter is required to perform the operation on the main frame of the currently loaded web page.
public static final int FOCUSED_FRAME_ID
frameId
parameter is required to perform the operation on the focused frame of the currently loaded web page.
public Browser()
Browser
instance with default
BrowserContext
and
BrowserType.HEAVYWEIGHT
type. This method is equivalent of:
new Browser(BrowserType.HEAVYWEIGHT)
BrowserException
- when unexpected error happens during instance instantiation.
BrowserException
- when another
Browser
instance is already created and configured with the different
BrowserContext
instance, that uses the same Chromium profile directory.
java.lang.IllegalStateException
- when in JavaFX on Mac OS X the Browser instance is initialized in JavaFX UI thread.
public Browser(BrowserContext browserContext)
Browser
instance with specified
BrowserContext
. This method is equivalent of:
new Browser(BrowserType.HEAVYWEIGHT, browserContext)
browserContext
- context associated with the instance. Cannot be
null
.
-与实例关联的上下文。不可能是 。
BrowserException
- when unexpected error happens during instance instantiation.
BrowserException
- when another
Browser
instance is already created and configured with the different
BrowserContext
instance, that uses the same Chromium profile directory.
java.lang.IllegalArgumentException
- when
browserContext
is
null
.
java.lang.IllegalStateException
- when in JavaFX on Mac OS X the Browser instance is initialized in JavaFX UI thread.
public Browser(BrowserType browserType)
Browser
instance with default
BrowserContext
and specified
BrowserType
. This method is equivalent of:
new Browser(browserType, BrowserContext.defaultContext())
browserType
- represents type of the
Browser
instance that describes in what mode Chromium engine will be initialized and embedded into Java application: as a lightweight (off-screen) or as a heavyweight (windowed) component.
-表示实例的类型,该实例描述了Chromium引擎将以哪种模式初始化并嵌入到Java应用程序中:作为轻量级(屏幕外)或重量级(窗口式)组件。
BrowserException
- when unexpected error happens during instance instantiation.
BrowserException
- when another
Browser
instance is already created and configured with the different
BrowserContext
instance, that uses the same Chromium profile directory.
java.lang.IllegalStateException
- when in JavaFX on Mac OS X the Browser instance is initialized in JavaFX UI thread.
public Browser(BrowserType browserType, BrowserContext browserContext)使用指定的BrowserContext和BrowserType创建一个新的Browser实例。
browserType
- represents type of the
Browser
instance that describes in what mode Chromium engine will be initialized and embedded into Java application: as a lightweight (off-screen) or as a heavyweight (windowed) component.
-表示实例的类型,该实例描述了Chromium引擎将以哪种模式初始化并嵌入到Java应用程序中:作为轻量级(屏幕外)或重量级(窗口式)组件。
browserContext
- context associated with the instance. Cannot be
null
.
-与实例关联的上下文。不可能是 。
BrowserException
- when unexpected error happens during instance instantiation.
BrowserException
- when another
Browser
instance is already created and configured with the different
BrowserContext
instance, that uses the same Chromium profile directory.
java.lang.IllegalArgumentException
- when
browserContext
is
null
.
java.lang.IllegalStateException
- when in JavaFX on Mac OS X the Browser instance is initialized in JavaFX UI thread.
public static void invokeAndWaitFinishLoadingMainFrame(Browser browser, Callback<Browser> task)
task
that must initiate web page loading, and waits until the main frame of the web page is loaded completely or until the timeout is reached.
Use this method when you need to perform some action that initiates web page loading and you have to wait until the web page is loaded completely. If the given task
doesn't cause web page loading or the web page loading has been failed for some reasons, then this method will block current thread execution until timeout is reached (by default 45 seconds).
Important: Use this method for loading web pages only.
browser
- a
Browser
instance in which a new web page must be loaded/reloaded. Cannot be
null
.
-必须加载/重新加载新网页的实例。不可能是 。
task
- an action that causes web page load/reload. Cannot be
null
.
-导致网页加载/重新加载的操作。不可能是 。
java.lang.IllegalArgumentException
- when
browser
or
task
is
null
.
public static void invokeAndWaitFinishLoadingMainFrame(Browser browser, Callback<Browser> task, int timeoutInSeconds)
task
that must initiate web page loading, and waits until the main frame of the web page is loaded completely or until the given
timeoutInSeconds
is reached.
Use this method when you need to perform some action that initiates web page loading and you have to wait until the web page is loaded completely. If the given task
doesn't cause web page loading or the web page loading has been failed for some reasons, then this method will block current thread execution until timeoutInSeconds
is reached.
Important: Use this method for loading web pages only.
browser
- a
Browser
instance in which a new web page must be loaded/reloaded. Cannot be
null
.
-必须加载/重新加载新网页的实例。不可能是 。
task
- an action that causes web page load/reload. Cannot be
null
.
-导致网页加载/重新加载的操作。不可能是 。
timeoutInSeconds
- timeout in seconds.
-超时(以秒为单位)。
java.lang.IllegalArgumentException
- when
browser
or
task
is
null
.
public BrowserType getType()
public void setSize(int width, int height)
width
- width of the Browser's view in pixels. Cannot be negative.
-浏览器视图的宽度(以像素为单位)。不能为负。
height
- height of the Browser's view in pixels. Cannot be negative.
-浏览器视图的高度(以像素为单位)。不能为负。
java.lang.IllegalArgumentException
- when
width
or
height
is negative.
public void addTitleListener(TitleListener listener)
listener
is
null
, no exception is thrown and no action is performed.
listener
- the browser title listener.
-浏览器标题侦听器。
public void removeTitleListener(TitleListener listener)
listener
- the browser title listener.
-浏览器标题侦听器。
public java.util.List<TitleListener> getTitleListeners()
TitleListener
s or an empty list if no browser title listeners are currently registered.
此浏览器的所有s或一个空列表(如果当前未注册任何浏览器标题侦听器)。
public void addStatusListener(StatusListener listener)
listener
is
null
, no exception is thrown and no action is performed.
listener
- the browser status listener.
-浏览器状态侦听器。
public void removeStatusListener(StatusListener listener)
listener
- the browser status listener.
-浏览器状态侦听器。
public java.util.List<StatusListener> getStatusListeners()
StatusListener
s or an empty list if no browser status listeners are currently registered.
此浏览器的所有s或一个空列表(如果当前未注册任何浏览器状态侦听器)。
public void addUploadProgressListener(UploadProgressListener listener)
listener
is
null
, no exception is thrown and no action is performed.
listener
- the upload progress listener.
-上传进度监听器。
public void removeUploadProgressListener(UploadProgressListener listener)
listener
- the upload progress listener.
-上传进度监听器。
public java.util.List<UploadProgressListener> getUploadProgressListeners()
UploadProgressListener
s or an empty list if no upload progress listeners are currently registered.
此浏览器的所有s或一个空列表(如果当前未注册任何上传进度侦听器)。
public void addLoadListener(LoadListener listener)
listener
is
null
, no exception is thrown and no action is performed.
listener
- the browser load listener.
-浏览器负载监听器。
public void removeLoadListener(LoadListener listener)
listener
- the browser load listener.
-浏览器负载监听器。
public java.util.List<LoadListener> getLoadListeners()
LoadListener
s or an empty list if no load listeners are currently registered.
此浏览器的所有s或一个空列表(如果当前未注册任何负载侦听器)。
public void addScriptContextListener(ScriptContextListener listener)
listener
to receive script context events from this browser instance.
If
listener
is
null
, no exception is thrown and no action is performed.
listener
- the script context listener.
-脚本上下文侦听器。
public void removeScriptContextListener(ScriptContextListener listener)
listener
- the script context listener.
-脚本上下文侦听器。
public java.util.List<ScriptContextListener> getScriptContextListeners()
ScriptContextListener
s or an empty list if no script context listeners are currently registered.
浏览器的所有s或一个空列表(如果当前未注册任何脚本上下文侦听器)。
public void addRenderListener(RenderListener listener)
listener
is
null
, no exception is thrown and no action is performed.
listener
- the browser render listener.
-浏览器渲染监听器。
public void removeRenderListener(RenderListener listener)
listener
- the browser render listener.
-浏览器渲染监听器。
public java.util.List<RenderListener> getRenderListeners()
RenderListener
s or an empty list if no render listeners are currently registered.
此浏览器的所有s或一个空列表(如果当前未注册任何渲染侦听器)。
public void addConsoleListener(ConsoleListener listener)
listener
is
null
, no exception is thrown and no action is performed.
listener
- the browser console listener.
-浏览器控制台侦听器。
public void removeConsoleListener(ConsoleListener listener)
listener
- the browser console listener.
-浏览器控制台侦听器。
public java.util.List<ConsoleListener> getConsoleListeners()
ConsoleListener
s or an empty list if no console listeners are currently registered.
此浏览器的所有s或一个空列表(如果当前未注册任何控制台侦听器)。
public FullScreenHandler getFullScreenHandler()
null
when there's no registered handlers.
public void setFullScreenHandler(FullScreenHandler handler)
handler
- a new full-screen handler. Can be
null
.
-新的全屏处理程序。可 。
public PopupHandler getPopupHandler()
null
. By default returns
null
.
public void setPopupHandler(PopupHandler handle)
handle
- a new popup handler. Can be
null
.
-一个新的弹出处理程序。可 。
public ContextMenuHandler getContextMenuHandler()
null
if no context menu handler is currently registered. By default returns
null
.
public void setContextMenuHandler(ContextMenuHandler handler)
handler
- new context menu handler.
-新的上下文菜单处理程序。
public DownloadHandler getDownloadHandler()
null
if no file download handler is currently registered. By default this method returns
null
, so all file downloads are suppressed.
null
if no file download handler is currently registered.
已注册的文件下载处理程序,或者当前未注册任何文件下载处理程序。
public void setDownloadHandler(DownloadHandler handler)
handler
- the new file download handler.
-新的文件下载处理程序。
public PermissionHandler getPermissionHandler()
null
if no permission handler is current registered. By default, this method returns
null
which indicates that all permission requests will be denied.
null
if no permission handler is currently registered.
已注册的权限处理程序,或者当前未注册任何权限处理程序。
public void setPermissionHandler(PermissionHandler handler)
handler
- the new permission handler.
-新的权限处理程序。
public DialogHandler getDialogHandler()
null
if no dialog handler is currently registered. By default this method returns
null
, so all JavaScript dialogs are suppressed.
null
if no dialog handler is registered.
已注册的对话框处理程序,或者未注册任何对话框处理程序。
public void setDialogHandler(DialogHandler handler)
handler
- the new dialog handler.
-新的对话框处理程序。
public CookieStorage getCookieStorage()
public CacheStorage getCacheStorage()
public boolean isCommandEnabled(EditorCommand command)
true
if the
command
can be executed in the currently focused frame on the loaded web page. Most of the commands are always disabled for unfocused frames. There's no sense in checking whether command is enabled for unfocused frame. Use this method only to check whether a specified command can be used in the currently focused frame.
command
- the command to check.
-检查的命令。
false
if the
command
cannot be executed in the currently focused frame or there's no focused frame at all.
如果无法在当前关注的框架中执行或根本没有关注的框架。
java.lang.IllegalArgumentException
- when
command
is
null
.
public boolean executeCommand(EditorCommand command)
command
in the currently focused frame on the loaded web page. You can find out when
command
requires value by calling
EditorCommand.isValueRequired()
method.
command
- the command to execute.
-要执行的命令。
true
if
command
has been executed successfully.
如果已成功执行。
java.lang.IllegalArgumentException
- when
command
is
null
.
public boolean executeCommand(long frameId, EditorCommand command)
command
in the frame, specified by
frameId
. You can find out when
command
requires value by calling
EditorCommand.isValueRequired()
method.
frameId
- id of the frame, in which the
command
will be executed.
-将在其中执行的框架的ID。
command
- the command to execute.
-要执行的命令。
true
if
command
has been executed successfully.
如果已成功执行。
java.lang.IllegalArgumentException
- when
command
is
null
.
java.lang.IllegalArgumentException
- when
frameId
is invalid.
getFramesIds()
public boolean executeCommand(EditorCommand command, java.lang.String value)
command
with command
value
in the focused frame on the loaded web page. You can find out when
command
requires value by calling
EditorCommand.isValueRequired()
method.
command
- the command to execute.
-要执行的命令。
value
- a string that represents
command
value.
-表示值的字符串。
true
if
command
has been executed successfully.
如果已成功执行。
java.lang.IllegalArgumentException
- when
command
is
null
.
public boolean executeCommand(long frameId, EditorCommand command, java.lang.String value)
command
with command
value
in the frame specified by
frameId
. To find out whether
command
requires a value you can use the
EditorCommand.isValueRequired()
method.
frameId
- id of the frame, in which the
command
will be executed.
-将在其中执行的框架的ID。
command
- the command to execute.
-要执行的命令。
value
- a string that represents
command
value.
-表示值的字符串。
true
if
command
has been executed successfully.
如果已成功执行。
java.lang.IllegalArgumentException
- when
command
is
null
.
java.lang.IllegalArgumentException
- when
frameId
is invalid.
getFramesIds()
public LoadHandler getLoadHandler()
null
if no load handler is currently registered. By default this method returns
null
, so all web pages will be loaded as well.
null
if no load handler is currently registered.
已注册的负载处理程序,或者当前未注册任何负载处理程序。
public void setLoadHandler(LoadHandler handler)
LoadHandler
can be used to cancel some URL loading.
handler
- a new load handler. Can be
null
.
-一个新的负载处理程序。可 。
public java.lang.String getRemoteDebuggingURL()
remote-debugging-port=[port]
Chromium switch by calling
BrowserPreferences.setChromiumSwitches(String...)
method before creating any Browser instance.
Note: do not load this URL in other web browser applications such as Mozilla FireFox, IE, etc. This may cause native crash in Chrome Developers Tools server. It's recommended that you access the URL from Google Chrome 31+ or another JxBrowser Browser instance.
remote-debugging-port
switch wasn't specified.
Chrome开发者工具网页的URL,如果未指定switch,则可以调试当前浏览器实例的加载网页或空字符串。
public java.util.List<java.lang.Long> getFramesIds()
public java.util.List<java.lang.Long> getFramesIds(long frameId)
frameId
. Each frame on the loaded document has corresponding unique frame ID that can be used to work with this frame to get its document, execute JavaScript code on this frame, etc.
You must call this method only when the entire document of a specified URL you navigate to is loaded completely. If you call this method when the document is still loading, you may receive only already loaded frames IDs. Each document has at least one frame (main frame).
public SearchResult findText(SearchParams params)
findText(SearchParams, SearchResultCallback)
method
params
- search parameters, such as text to search, case-sensitive, search direction.
-搜索参数,例如要搜索的文本,区分大小写,搜索方向。
java.lang.IllegalArgumentException
- when
params
is
null
.
public void findText(SearchParams params, SearchResultCallback callback)
Doesn't block current thread when invoked. Search result updates can be processed in the SearchResultCallback
implementation passed as a callback
parameter. If the search procedure takes a certain time, it can be interrupted by invoking the stopFindingText(StopFindAction)
method.
params
- search parameters, such as text to search, case-sensitive, search direction.
-搜索参数,例如要搜索的文本,区分大小写,搜索方向。
callback
- a callback object which allows processing the search result. Can be
null
.
-允许处理搜索结果的回调对象。可 。
java.lang.IllegalArgumentException
- when
params
is
null
.
public void stopFindingText(StopFindAction action)
action
- determines action, which will be applied to the selected match.
-确定将应用于所选匹配项的操作。
public java.lang.String getSelectedText()
public java.lang.String getSelectedText(long frameId)
frameId
or empty string if there is no selection.
frameId
- unique identifier of a web frame on the currently loaded web page.
-当前加载的网页上的网络框架的唯一标识符。
frameId
or empty string if there is no selection.
框架的选定文本,由指定;如果没有选择,则为空字符串。
public java.lang.String getSelectedHTML()
public java.lang.String getSelectedHTML(long frameId)
frameId
or empty string if there is no selection.
frameId
- unique identifier of a web frame on the currently loaded web page.
-当前加载的网页上的网络框架的唯一标识符。
frameId
or empty string if there is no selection.
框架的选定HTML,由指定;如果没有选择,则为空字符串。
public PluginManager getPluginManager()
public MediaStreamDeviceManager getMediaStreamDeviceManager()
public PrintHandler getPrintHandler()
null
when there's no installed handler. By default it returns
null
.
null
.
当前的打印处理程序或。
public void setPrintHandler(PrintHandler handler)
handler
- a print handler. You can set
null
to enable silent mode where print dialog isn't displayed and web page is printed using default system print settings. On different platforms default system print settings can be different.
-打印处理程序。您可以设置为启用静音模式,其中不显示打印对话框,并且使用默认系统打印设置来打印网页。在不同平台上,默认系统打印设置可以不同。
public void print()
public void print(long frameId)
frameId
on the currently loaded web page. It does nothing if the web page is still being loaded.
If you invoke this method while previous printing hasn't been finished/canceled yet, it will cancel previous printing. You should wait until previous printing is finished before calling this method again.
frameId
- unique identifier of a web frame on the currently loaded web page.
-当前加载的网页上的网络框架的唯一标识符。
java.lang.IllegalArgumentException
- when
frameId
is invalid.
getFramesIds()
public BrowserPreferences getPreferences()
public void setPreferences(BrowserPreferences preferences)
preferences
will be applied to the current Browser instance only.
preferences
- the new web preferences. Cannot be
null
.
-新的网络偏好设置。不可能是 。
java.lang.IllegalArgumentException
- when
preferences
is
null
.
public boolean saveWebPage(java.lang.String filePath, java.lang.String dirPath, SavePageType saveType)
LoadListener.onFinishLoadingFrame()
to make sure that web page is loaded completely.
filePath
- the full path of a file in which the web page will be saved. If absolute path to the file does not exist, it will be created.
-将在其中保存网页的文件的完整路径。如果文件的绝对路径不存在,将创建该文件。
dirPath
- the full path of the directory in which resources (e.g. images, css) of the web page will be saved. If the directory does not exist, it will be created.
-将在其中保存网页资源(例如图片,css)的目录的完整路径。如果目录不存在,将创建该目录。
saveType
- determines how the web page will be saved: as HTML file with required resources (e.g. images, css etc.), a single HTML or MHTML file.
-确定网页的保存方式:单个HTML或MHTML文件作为具有所需资源(例如图像,CSS等)的HTML文件。
true
if saving process has been initialized successfully, otherwise -
false
.
如果保存过程已成功初始化,否则-。
java.lang.IllegalArgumentException
- when
filePath
is
null
or empty,
dirPath
is
null
or empty,
saveType
is
null
.
public BrowserContext getContext()
BrowserContext
associated with this browser instance.
public DOMDocument getDocument()
null
if the web page is not loaded or not available (e.g. PDF document is loaded).
null
.
当前加载网页的主框架的HTML文档或。
public DOMDocument getDocument(long frameId)
null
if the web page is not loaded or not available (e.g. PDF document is loaded).
frameId
- unique identifier of a web frame on the currently loaded web page.
-当前加载的网页上的网络框架的唯一标识符。
null
.
当前加载的网页或上指定框架的HTML文档。
java.lang.IllegalArgumentException
- when
frameId
is invalid.
getFramesIds()
public boolean isSandboxEnabled()
public DOMNodeAtPoint getNodeAtPoint(int x, int y)
x
and
y
parameters at the coordinate space of the loaded web page. Returns
null
if there's no Node at the passed location on the loaded web page.
x
- the x-coordinate of the location.
-位置的x坐标。
y
- the y-coordinate of the location.
-位置的y坐标。
DOMNodeAtPoint
object that contains information about Node at the location or
null
when there's no Node at this location.
包含有关该位置上的Node或该位置上没有Node的信息的对象。
public DOMNodeAtPoint getNodeAtPoint(java.awt.Point point)
point
parameter at the coordinate space of the loaded web page. Returns
null
if there's no Node at the passed location on the loaded web page.
point
- the point defining the top-left corner of the location, given in the coordinate space of the loaded web page.
-定义位置左上角的点,在加载的网页的坐标空间中给出。
DOMNodeAtPoint
object that contains information about Node at the location or
null
when there's no Node at this location.
包含有关该位置上的Node或该位置上没有Node的信息的对象。
java.lang.IllegalArgumentException
- when
point
parameter is
null
.
public void dispose()
Browser.executeJavaScriptAndReturnValue()
method that takes 10 seconds to get return value from JavaScript and in another thread you dispose Browser instance using
Browser.dispose()
method, the method will block current thread execution and wait until
Browser.executeJavaScriptAndReturnValue()
method has finished its execution.
When Browser instance is being disposed you cannot invoke its methods. If you do it, you will get
IllegalStateException
exception.
isDisposed()
public boolean dispose(boolean checkBeforeUnload)
checkBeforeUnload
parameter is
true
and current document has the
window.onbeforeunload()
method implemented, Browser engine will initiate displaying before unload confirmation dialog to ask user whether current document should be closed and current thread execution will be blocked until the
DialogHandler.onBeforeUnload(UnloadDialogParams)
method is completed. By default the
{@link DialogHandler#onBeforeUnload(UnloadDialogParams)}
method is executed in UI thread. Therefore you
must invoke the
dispose()
method in non-UI thread to avoid deadlock.
If user cancelles closing current document, the Browser instance will not be disposed. If current document doesn't have the
window.onbeforeunload()
method implemented or user confirms closing current document, the Browser instance will be disposed.
Note, that if the
DialogHandler
field of current Browser instance is set to
null
and current document does have the
window.onbeforeunload()
method implemented, the Browser instance will not be disposed.
Note, that Browser instance will always be disposed if customer haven't performed any actions with document before this method is invoked, e.g. focused, clicked, etc.
If current Browser instance is disposed, does nothing and returns
true
.
checkBeforeUnload
- determines if Browser engine dispatches the beforeUnload event before and waits for result before disposing current Browser instance.
-确定浏览器引擎是否在分派当前浏览器实例之前分派beforeUnload事件并等待结果。
true
if current browser instance is disposed.
当前的浏览器实例是否已处置。
dispose()
,
isDisposed()
,
setDialogHandler(DialogHandler)
public boolean isDisposed()
true
when the current browser instance is disposed.
public void addDisposeListener(DisposeListener<Browser> listener)
listener
is
null
, no exception is thrown and no action is performed.
listener
- the browser dispose listener.
-浏览器配置侦听器。
public void removeDisposeListener(DisposeListener<Browser> listener)
listener
- the browser dispose listener.
-浏览器配置侦听器。
public java.util.List<DisposeListener<Browser>> getDisposeListeners()
DisposeListener
s or an empty list if no browser dispose listeners are currently registered.
此浏览器的所有s,如果当前未注册用于处置监听器的浏览器,则为空列表。
public void loadURL(java.lang.String url)
LoadListener.onFinishLoadingFrame()
event.
url
- the URL of the resource to display. The parameter cannot be
null
.
-要显示的资源的URL。参数不能为。
java.lang.IllegalArgumentException
- when
url
is
null
.
public void loadURL(long frameId, java.lang.String url)
frameId
on the currently loaded web page to a resource identified by the
url
. By default browser is not allowed to render a web page from a different domain in
<frame> or <iframe>
. This behavior is enabled to avoid clickjacking attacks. To determine whether the page can be displayed in a frame, the
X-Frame-Options
header is used. The possible values for
X-Frame-Options
are:
LoadListener.onFinishLoadingFrame()
event.
frameId
- unique identifier of a web frame on the currently loaded web page.
-当前加载的网页上的网络框架的唯一标识符。
url
- the URL of the resource to display. The parameter cannot be
null
.
-要显示的资源的URL。参数不能为。
java.lang.IllegalArgumentException
- when
url
is
null
.
java.lang.IllegalArgumentException
- when
frameId
is invalid.
getFramesIds()
public void loadURL(LoadURLParams params)
LoadURLParams.getURL()
.
This method is invoked asynchronously. To make sure that the web page is loaded completely, use the
LoadListener.onFinishLoadingFrame()
event.
params
- contains parameters such as URL and POST data. The parameter cannot be
null
.
-包含URL和POST数据等参数。参数不能为。
java.lang.IllegalArgumentException
- when
params
is
null
.
public void loadHTML(java.lang.String html)
html
string. The currently loaded web page will be unloaded and new HTML content will be displayed. This operation is alternative for:
loadHTML(new LoadHTMLParams("html...", "text/html", "UTF-8", null, false));This method is asynchronous. If Browser instance doesn't have a text/html document (e.g. the PDF document is loaded), this method does nothing.
html
- contains parameters such as HTML, Encoding, BaseURL etc. The parameter cannot be
null
.
-包含HTML,Encoding,BaseURL等参数。该参数不能为。
java.lang.IllegalArgumentException
- when
params
is
null
.
public void loadHTML(long frameId, java.lang.String html)
html
content into the specified frame of the currently loaded document. The web frame will be unloaded and new HTML content will be displayed. This operation is alternative for:
loadHTML(frameId, new LoadHTMLParams("html...", "UTF-8", null));This method is asynchronous. If Browser instance doesn't have a text/html document (e.g. the PDF document is loaded), this method does nothing.
frameId
- unique identifier of a web frame on the currently loaded web page.
-当前加载的网页上的网络框架的唯一标识符。
html
- contains parameters such as HTML, Encoding, BaseURL etc. The parameter cannot be
null
.
-包含HTML,Encoding,BaseURL等参数。该参数不能为。
java.lang.IllegalArgumentException
- when
params
is
null
.
java.lang.IllegalArgumentException
- when
frameId
is invalid.
getFramesIds()
public void loadHTML(LoadHTMLParams params)
LoadHTMLParams.getHTML()
content into the main frame of the currently loaded document. The currently loaded web page will be unloaded and new HTML content will be displayed.
This method is asynchronous. If Browser instance doesn't have a document, this method does nothing.
params
- contains parameters such as HTML, Encoding, BaseURL etc. The parameter cannot be
null
.
-包含HTML,Encoding,BaseURL等参数。该参数不能为。
java.lang.IllegalArgumentException
- when
params
is
null
.
public void loadHTML(long frameId, LoadHTMLParams params)
LoadHTMLParams.getHTML()
content into the specified frame of the currently loaded document. The web frame with
frameId
will be unloaded and new HTML content will be displayed in it.
This method is asynchronous. If Browser instance doesn't have a text/html document (e.g. the PDF document is loaded), this method does nothing.
frameId
- unique identifier of a web frame on the currently loaded web page.
-当前加载的网页上的网络框架的唯一标识符。
params
- contains parameters such as HTML, Encoding, BaseURL etc. The parameter cannot be
null
.
-包含HTML,Encoding,BaseURL等参数。该参数不能为。
java.lang.IllegalArgumentException
- when
params
is
null
.
java.lang.IllegalArgumentException
- when
frameId
is invalid.
getFramesIds()
public void loadData(LoadDataParams params)
LoadDataParams.getData()
string with specified mime type and optional text encoding into the main frame on the currently loaded document.
This method is asynchronous. If Browser instance doesn't have a text/html document (e.g. the PDF document is loaded), this method does nothing.
params
- contains parameters such as data string, mime type, text encoding and base URL. The parameter cannot be
null
.
-包含参数,例如数据字符串,mime类型,文本编码和基本URL。参数不能为。
java.lang.IllegalArgumentException
- when
params
is
null
.
public void loadData(long frameId, LoadDataParams params)
LoadDataParams.getData()
string with specified mime type and optional text encoding into the specified frame on the currently loaded document.
This method is asynchronous. If Browser instance doesn't have a text/html document (e.g. the PDF document is loaded), this method does nothing.
frameId
- unique identifier of a web frame on the currently loaded web page.
-当前加载的网页上的网络框架的唯一标识符。
params
- contains parameters such as data string, mime type, text encoding and base URL. The parameter cannot be
null
.
-包含参数,例如数据字符串,mime类型,文本编码和基本URL。参数不能为。
java.lang.IllegalArgumentException
- when
params
is
null
.
java.lang.IllegalArgumentException
- when
frameId
is invalid.
getFramesIds()
public java.lang.String getHTML()
public java.lang.String getHTML(long frameId)
frameId
- unique identifier of a web frame on the currently loaded web page.
-当前加载的网页上的网络框架的唯一标识符。
java.lang.IllegalArgumentException
- when
frameId
is invalid.
getFramesIds()
public java.lang.String getURL()
public void executeJavaScript(java.lang.String javaScript)
javaScript
in the context of the current page. This method is executed asynchronously, so when this method finish its execution there's no guaranty that passed script also has finished its execution.
If Browser instance doesn't have a text/html document (e.g. the PDF document is loaded), this method does nothing.
javaScript
- a string that represents JavaScript code to be executed.
-表示要执行的JavaScript代码的字符串。
java.lang.IllegalArgumentException
- when
javaScript
is
null
.
public JSValue executeJavaScriptAndReturnValue(java.lang.String javaScript)
javaScript
in the context of the current page and returns the result of JavaScript execution as
JSValue
object. This method blocks the current thread execution and waits until passed
javaScript
finishes its execution. This method never returns
null
. If JavaScript return value is null, then this method returns a valid
JSValue
object. To make sure that it's
null
you can use
JSValue.isNull()
method.
If Browser instance doesn't have a text/html document (e.g. the PDF document is loaded), this method does nothing.
javaScript
- a string that represents JavaScript code to be executed.
-表示要执行的JavaScript代码的字符串。
java.lang.IllegalArgumentException
- when
javaScript
is
null
.
java.lang.IllegalStateException
- when script context is destroyed.
public void executeJavaScript(long frameId, java.lang.String javaScript)
javaScript
in the context of the web frame identified by
frameId
. This method is executed asynchronously, so when this method finish its execution there's no guaranty that passed script also has finished its execution.
If Browser instance doesn't have a text/html document (e.g. the PDF document is loaded), this method does nothing.
frameId
- unique identifier of a web frame on the currently loaded web page.
-当前加载的网页上的网络框架的唯一标识符。
javaScript
- a string that represents JavaScript code to be executed.
-表示要执行的JavaScript代码的字符串。
java.lang.IllegalArgumentException
- when
javaScript
is
null
.
java.lang.IllegalArgumentException
- when
frameId
is invalid.
java.lang.IllegalStateException
- when renderer is closed.
getFramesIds()
public JSValue executeJavaScriptAndReturnValue(long frameId, java.lang.String javaScript)
javaScript
in the context of the web frame identified by
frameId
and returns the result of JavaScript execution as
JSValue
object. This method blocks the current thread execution and waits until passed
javaScript
finishes its execution. This method never returns
null
. If JavaScript return value is null, then this method returns a valid
JSValue
object. To make sure that it's
null
you can use
JSValue.isNull()
method.
If Browser instance doesn't have a text/html document (e.g. the PDF document is loaded), this method does nothing.
frameId
- unique identifier of a web frame on the currently loaded web page.
-当前加载的网页上的网络框架的唯一标识符。
javaScript
- a string that represents JavaScript code to be executed.
-表示要执行的JavaScript代码的字符串。
java.lang.IllegalArgumentException
- when
javaScript
is
null
.
java.lang.IllegalArgumentException
- when
frameId
is invalid.
java.lang.IllegalStateException
- when script context is destroyed.
getFramesIds()
public JSContext getJSContext()
null
if no main frame is available or JavaScript context doesn't exist for main frame (e.g. the web page doesn't contain any JavaScript code at all).
JavaScript context is created automatically when JavaScript code is executed on the web page. If frame doesn't have JavaScript code, then method returns
null
. To force JavaScript context creation on the web page without JavaScript, you can call the
executeJavaScriptAndReturnValue(String)
method.
null
if no context is available for main frame.
主机的JavaScript上下文,或者如果主机没有上下文。
public JSContext getJSContext(long frameId)
frameId
on the currently loaded web page. Returns
null
if there's no frame with the
frameId
or JavaScript context isn't available for this frame.
JavaScript context is created automatically when JavaScript code is executed on the web page. If frame doesn't have JavaScript code, then method returns
null
. To force JavaScript context creation on the web page without JavaScript, you can call the
executeJavaScriptAndReturnValue(String)
method.
frameId
- unique identifier of a web frame on the currently loaded web page.
-当前加载的网页上的网络框架的唯一标识符。
frameId
or
null
.
指定或的JavaScript上下文。
public java.lang.String getTitle()
public double getZoomLevel()
public void setZoomLevel(double zoomLevel)
www.a.com
web page and set zoom level to 2.5, then load the
www.b.org
web page, the zoom level for
www.b.org
web page will be reset to default value. When you load the
www.a.com
web page again, its zoom level will be restored to 2.5 automatically.
This method is executed asynchronously.
To zoom in use the positive zoom level. For example, 2.0, 1.5. To zoom out use the negative zoom level. For example, -1.0, -2.5.
Zoom level isn't a percentage value and 1.0 isn't equal to 100%. Zoom level is a Chromium level. To understand percentages for each zoom levels please see the following table:
25% : "default_zoom_level": -7.6035680338478615,
zoomLevel
- new zoom level value, e.g. 2.0, -1.5.
-新的缩放级别值,例如2.0,-1.5。
public void zoomIn()
public void zoomOut()
public void zoomReset()
public boolean isZoomEnabled()
true
if zoom functionality is enabled for this browser instance.
如果为此浏览器实例启用了缩放功能。
public void setZoomEnabled(boolean enabled)
To disable zoom functionality pass false
. In this case the browser instance will revert to the default zoom level, and all attempted zoom changes will be ignored.
enabled
- use
false
to revert to the default zoom level and disable zoom functionality. All attempted zoom changes will be ignored.
-用于恢复默认的缩放级别并禁用缩放功能。所有尝试的缩放更改都将被忽略。
public boolean isLoading()
true
when browser is loading resource.
public void stop()
public void goBack()
canGoBack()
public boolean canGoBack()
true
when browser can navigate back.
浏览器何时可以向后导航。
public void goForward()
canGoForward()
public boolean canGoForward()
true
when browser can navigate forward.
当浏览器可以向前导航时。
public boolean canGoToOffset(int offset)
offset
- the specified offset from the "current navigation entry". Can be negative.
-与“当前导航条目”的指定偏移量。可以为负。
true
when browser can navigate to the specified offset, otherwise
false
.
当浏览器可以导航到指定的偏移量时,否则。
public void goToOffset(int offset)
offset
is out of bounds.
offset
- the specified offset from the "current navigation entry" in the back/forward list of the current Browser instance.
-当前浏览器实例的后退/前进列表中与“当前导航条目”的指定偏移量。
public void goToIndex(int index)
index
is out of bounds.
index
- the specified absolute index in the back/forward list of the current Browser instance.
-当前浏览器实例的后退/前进列表中指定的绝对索引。
public int getNavigationEntryCount()
public int getCurrentNavigationEntryIndex()
public NavigationEntry getCurrentNavigationEntry()
null
. By default each Browser instance navigates to "about:blank" web page, so even if you don't load any web page this method should return
NavigationEntry
for initial "about:blank" web page.
public NavigationEntry getNavigationEntryAtIndex(int index)
index
in the back/forward list of the current Browser instance.
null
if there's no navigation entry at the specified
index
.
导航条目,或者在指定的位置没有导航条目。
public NavigationEntry getNavigationEntryAtOffset(int offset)
offset
from current in the back/forward list of the current Browser instance.
null
if there's no navigation entry at the specified
offset
.
导航条目,或者在指定的位置没有导航条目。
public boolean removeNavigationEntryAtIndex(int index)
index
in the back/forward list of the current Browser instance. If the
index
is the last committed index, this method does nothing and returns
false
.
public void reload()
reload(false)
.
reload(boolean)
public void reloadIgnoringCache()
reloadIgnoringCache(false)
.
reloadIgnoringCache(boolean)
public void reload(boolean checkForRepost)
checkForRepost
is
true
and the current web page has POST data the user it prompted to see if they really want to reload the page.
checkForRepost
- if
true
and the current web page has POST data the user is prompted to see if they really want to reload the page, otherwise - POST data will be sent without prompting the user.
-如果当前网页上有POST数据,则提示用户查看他们是否真的要重新加载该页面,否则-将发送POST数据而不会提示用户。
public void reloadIgnoringCache(boolean checkForRepost)
checkForRepost
is
true
and the current web page has POST data the user it prompted to see if they really want to reload the page.
checkForRepost
- if
true
and the current web page has POST data the user is prompted to see if they really want to reload the page, otherwise - POST data will be sent without prompting the user.
-如果当前网页上有POST数据,则提示用户查看他们是否真的要重新加载该页面,否则-将发送POST数据而不会提示用户。
public WebStorage getLocalWebStorage()
null
.
与主机或关联的本地Web存储。
public WebStorage getLocalWebStorage(long frameId)
null
.
frameId
- unique identifier of a web frame on the currently loaded web page.
-当前加载的网页上的网络框架的唯一标识符。
null
.
与主机或关联的本地Web存储。
java.lang.IllegalArgumentException
- when
frameId
is invalid.
getFramesIds()
public WebStorage getSessionWebStorage()
null
.
与主机或关联的会话Web存储。
public WebStorage getSessionWebStorage(long frameId)
null
.
frameId
- unique identifier of a web frame on the currently loaded web page.
-当前加载的网页上的网络框架的唯一标识符。
null
.
与主机或关联的会话Web存储。
java.lang.IllegalArgumentException
- when
frameId
is invalid.
getFramesIds()
public void replaceMisspelledWord(java.lang.String word)
word
. If there's no misspelled word under cursor, this method does nothing.
word
- a string that represents word for replacement.
-表示要替换的单词的字符串。
java.lang.IllegalArgumentException
- when
word
is
null
or empty string.
public boolean addWordToSpellCheckerDictionary(java.lang.String word)
word
- a string that represents word to add. Cannot be
null
or empty string.
-表示要添加的单词的字符串。不能为或为空字符串。
true
if word has been successfully added to user's dictionary. Returns
false
if word already in user's dictionary, not a UTF-8 string, longer than 99 bytes, leading/trailing whitespace, or empty.
如果单词已成功添加到用户词典中。返回用户字典中是否已有单词(不是UTF-8字符串),长度超过99个字节,前导/尾随空格或为空。
java.lang.IllegalArgumentException
- when
word
is
null
or empty string.
public boolean isAudioMuted()
true
when audio output for this Browser instance is muted.
true
when audio output for this Browser instance is muted,
false
otherwise.
当此浏览器实例的音频输出被静音时,否则。
public void setAudioMuted(boolean muted)
muted
-
true
when audio output must be muted,
false
otherwise.
-音频输出必须静音时,否则。
public boolean isAudioPlaying()
true
when the audio is currently playing on the loaded web page.
true
when the audio is currently playing on the loaded web page,
false
otherwise.
当前在加载的网页上正在播放音频时,否则。
public void forwardKeyEvent(BrowserKeyEvent event)
event
to currently focused HTML element on the loaded web page. Even if the web page is being loaded or there's no focused HTML element on the loaded web page, the method still forwards key event to Chromium engine.
event
- the key event to forward. Cannot be
null
.
-要转发的关键事件。不可能是 。
java.lang.IllegalArgumentException
- when
event
is
null
.
public void forwardMouseEvent(BrowserMouseEvent event)
event
to the loaded web page. Even if the web page is being loaded or there's no focused HTML element on the loaded web page, the method still forwards mouse event to Chromium engine.
event
- the mouse event to forward. Cannot be
null
.
-要转发的鼠标事件。不可能是 。
java.lang.IllegalArgumentException
- when
event
is
null
.
public RenderProcessInfo getRenderProcessInfo()
The information about render process is collected at the moment of the method invocation. You must call this method again if you need to get the up to date information.
null
if there's no render process associated with the current Browser instance.
返回提供有关渲染过程信息的对象。如果当前浏览器实例没有关联的渲染过程,则返回。
public java.lang.String getCustomStyleSheet()
setCustomStyleSheet(String)
method. By default, returns an empty string.
public void setCustomStyleSheet(java.lang.String customStyleSheet)
customStyleSheet
string that represents a custom style sheet (CSS) into every HTML document loaded in this instance. The given CSS will be applied during loading HTML document. If the document is already loaded, the CSS will not be applied. The document must be reloaded to apply the CSS.
If CSS property defined in the given customStyleSheet
string already exists on the loaded HTML document, then the existing CSS property won't be overriden. The CSS properties defined in the given customStyleSheet
string will be applied only if these properties aren't defined on the loaded document.
To reset CSS pass empty string as parameter.
customStyleSheet
- a string that represents CSS (e.g.
"body{background-color:orange;}"
). Cannot be
null
.
-代表CSS的字符串(例如)。不可能是 。
java.lang.IllegalArgumentException
- when
customStyleSheet
is
null
.
public java.lang.String getUserAgent()
public void setUserAgent(java.lang.String userAgent)
BrowserPreferences.setUserAgent(String)
, then a default user agent string will be used. User agent string passed as an argument overrides value set by the
BrowserPreferences.setUserAgent(String)
This method is invoked synchronously.
userAgent
- a new user agent string.
-新的用户代理字符串。
java.lang.IllegalArgumentException
- when
userAgent
is
null
or empty.
public java.lang.String getAcceptLanguage()
BrowserContext.getAcceptLanguage()
instead.
public void setAcceptLanguage(java.lang.String acceptLanguage)
acceptLanguage
parameter doesn't support the RFC 7231 Standard. Use BrowserContext.setAcceptLanguage(String)
instead.
BrowserContextParams
, then a default accept language will be used. Accept language passed as an argument overrides value set by
BrowserContextParams.setAcceptLanguage(String)
method or the
BrowserContextParams.BrowserContextParams(String, String)
constructor.
acceptLanguage
- a new accept language string.
-新的接受语言字符串。
java.lang.IllegalArgumentException
- when
acceptLanguage
is
null
, blank, empty, or is not supported by Chromium engine.