Interface Browser
BrowserFactory.
Embed the browser in your UI by adding getComponent() to a Swing container.
As a general rule, user code should pass a BrowserListener to BrowserFactory and wait for
onPageLoaded before calling any other methods on this class.
This also handles runtime browser installation under the hood.
Initial content must be set through BrowserFactory create methods, not from loadUrl/loadHtml.
Methods loadUrl/loadHtml have no effect when called before browser initialization finishes.
They should be used to update the content after initial content was rendered.
To send messages to the page, use sendMessage or runJsScript.
To receive messages initiated by the page, pass a BrowserListener to BrowserFactory and override
onMessage.
From the page, call bmMessage(String message, function callback).
Argument callback is optional and can be used to receive a response from Java code.
See velox.gui.debug.DebugUi in the main module and browser-submit-demo.html for usage examples.
Threading. The browser-control methods defined here can be called from any thread.
getComponent() and the returned component must be accessed on the Swing EDT.
-
Method Summary
Modifier and TypeMethodDescriptionvoidvoidvoidrunJsScript(String script, Consumer<String> callback) Evaluates the given script in the main frame and passes the result to callback.voidsendMessage(String jsFunction, String message, Consumer<String> callback) Call the given JS function on the loaded page with the given message.
-
Method Details
-
getComponent
JComponent getComponent()- Returns:
- The Swing component rendering the browser. Must be accessed on the Swing EDT.
-
loadUrl
- Throws:
BrowserNotInstalledException- if the browser binaries are not yet installed.
-
loadHtml
- Parameters:
html- Content to render.Limitation: HTML size here is limited to ~1 MB in CEF.
- Throws:
BrowserNotInstalledException- if the browser binaries are not yet installed.
-
sendMessage
Call the given JS function on the loaded page with the given message. Get the return value in the callback.- Throws:
BrowserNotInstalledException- if the browser binaries are not yet installed.
-
runJsScript
Evaluates the given script in the main frame and passes the result to callback.To debug script errors, set the debug level to TRACE.
- Throws:
BrowserNotInstalledException- if the browser binaries are not yet installed.
-