Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ plugins {
id("org.jetbrains.kotlin.plugin.compose") version "2.0.0"
}

val jxBrowserVersion by extra { "8.11.0" } // The version of JxBrowser used in the examples.
val jxBrowserVersion by extra { "8.12.0" } // The version of JxBrowser used in the examples.
val guavaVersion by extra { "29.0-jre" } // Some of the examples use Guava.

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public void windowClosing(WindowEvent e) {

private static void loadHtmlAndWait(Browser browser, String html) {
var latch = new CountDownLatch(1);
browser.mainFrame().ifPresent(mainFrame -> mainFrame.loadHtml(html));
browser.navigation().on(FrameLoadFinished.class, event -> latch.countDown());
browser.navigation().loadHtml(html);
awaitUninterruptibly(latch);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public void windowClosing(WindowEvent e) {

private static void loadHtmlAndWait(Browser browser, String html) {
var latch = new CountDownLatch(1);
browser.mainFrame().ifPresent(mainFrame -> mainFrame.loadHtml(html));
browser.navigation().on(FrameLoadFinished.class, event -> latch.countDown());
browser.navigation().loadHtml(html);
awaitUninterruptibly(latch);
}
}
16 changes: 10 additions & 6 deletions examples/src/main/java/com/teamdev/jxbrowser/examples/DomForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,15 @@ public void windowClosing(WindowEvent e) {
element.findElementByName("lastName").ifPresent(lastName ->
lastName.attributes().put("value", "Doe"));
}));
browser.mainFrame().ifPresent(mainFrame ->
mainFrame.loadHtml("<html><body><form name=\"myForm\">" +
"First name: <input type=\"text\" name=\"firstName\"/><br/>" +
"Last name: <input type=\"text\" name=\"lastName\"/><br/>" +
"<input type=\"button\" value=\"Save\"/>" +
"</form></body></html>"));
browser.navigation().loadHtml("""
<html>
<body>
<form name="myForm">
First name: <input type="text" name="firstName"/><br/>
Last name: <input type="text" name="lastName"/><br/>
<input type="button" value="Save"/></form>
</body>
</html>
""");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ public static void main(String[] args) {
try (var engine = Engine.newInstance(OFF_SCREEN)) {
var browser = engine.newBrowser();

browser.mainFrame().ifPresent(mainFrame -> mainFrame.loadHtml(
"<html><body><a href='#' id='link' title='link title'>Link</a></body></html>"));
browser.navigation().loadHtml("""
<html>
<body>
<a href='#' id='link' title='link title'>Link</a>
</body>
</html>
""");

browser.mainFrame()
.flatMap(Frame::document)
.flatMap(Document::documentElement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private static void printEventDetails(Event event) {
private static void loadHtmlAndWait(Browser browser) {
var latch = new CountDownLatch(1);
browser.navigation().on(FrameLoadFinished.class, event -> latch.countDown());
browser.mainFrame().ifPresent(mainFrame -> mainFrame.loadHtml(HTML));
browser.navigation().loadHtml(HTML);
awaitUninterruptibly(latch);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private static void printEventDetails(Event event) {
private static void loadHtmlAndWait(Browser browser) {
var latch = new CountDownLatch(1);
browser.navigation().on(FrameLoadFinished.class, event -> latch.countDown());
browser.mainFrame().ifPresent(mainFrame -> mainFrame.loadHtml(HTML));
browser.navigation().loadHtml(HTML);
awaitUninterruptibly(latch);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,16 @@ public void windowClosing(WindowEvent e) {
event.frame().document().flatMap(Document::documentElement).ifPresent(element ->
element.findElementsByCssSelector("p").forEach(paragraph ->
System.out.println("innerHTML " + paragraph.innerHtml()))));
browser.mainFrame().ifPresent(mainFrame ->
mainFrame.loadHtml("<html><body><div id='root'>" +
"<p>paragraph1</p>" +
"<p>paragraph2</p>" +
"<p>paragraph3</p>" +
"</div></body></html>"));
browser.navigation().loadHtml("""
<html>
<body>
<div id='root'>
<p>paragraph1</p>
<p>paragraph2</p>
<p>paragraph3</p>
</div>
</body>
</html>
""");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,17 @@ public void windowClosing(WindowEvent e) {
((OptionElement) options[2]).select();
System.out.println(selectElement.innerHtml());
}));
browser.mainFrame().ifPresent(mainFrame ->
mainFrame.loadHtml("<html><body><select id='select-tag'>\n" +
" <option value=\"volvo\">Volvo</option>\n" +
" <option value=\"saab\">Saab</option>\n" +
" <option value=\"opel\">Opel</option>\n" +
" <option value=\"audi\">Audi</option>\n" +
"</select></body></html>"));
browser.navigation().loadHtml("""
<html>
<body>
<select id="select-tag">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
</body>
</html>
""");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ public void windowClosing(WindowEvent e) {
browser.set(OpenFileCallback.class, (params, tell) ->
tell.open(Paths.get("file.txt")));

browser.mainFrame().ifPresent(mainFrame ->
mainFrame.loadHtml("Please specify a file, or a set of files:<br>\n" +
"<input type='file' name='datafile' size='40'>"));
browser.navigation().loadHtml("""
Please specify a file, or a set of files:<br/>
<input type='file' name='datafile' size='40' />
""");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ public void windowClosing(WindowEvent e) {
frame.setVisible(true);
});

browser.mainFrame().ifPresent(mainFrame ->
mainFrame.loadHtml("<html><body><h1>Hello there!</h1></body></html>"));
browser.navigation().loadHtml("""
<html>
<body>
<h1>Hello there!</h1>
</body>
</html>
""");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ public void windowClosing(WindowEvent e) {
frame.setLocationRelativeTo(null);
frame.setVisible(true);

browser.mainFrame().ifPresent(mainFrame ->
mainFrame.loadHtml("<html><body><a href='#' onclick='window.print();'>" +
"Print</a></body></html>"));
browser.navigation().loadHtml("""
<html>
<body>
<a href="#" onclick="window.print();">Print</a>
</body>
</html>
""");
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ public void windowClosing(WindowEvent e) {
System.out.println("Error start index: " + checkResult.location());
System.out.println("Error length: " + checkResult.length());
}));
browser.mainFrame().ifPresent(mainFrame -> {
mainFrame.loadHtml("<html><body>" +
"<textarea autofocus rows='20' cols='30'>Smple text with mitake.</textarea>" +
"</body></html>");
});
browser.navigation().loadHtml("""
<html>
<body>
<textarea autofocus rows='20' cols='30'>
Smple text with mitake.
</textarea>
</body>
</html>
""");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,15 @@ public void windowClosing(WindowEvent e) {
var location = params.location();
popupMenu.show(view, location.x(), location.y());
});
browser.mainFrame().ifPresent(mainFrame ->
mainFrame.loadHtml("<html><body><textarea rows='20' cols='30'>" +
"Smple text with mitake.</textarea></body></html>"));

browser.navigation().loadHtml("""
<html>
<body>
<textarea rows='20' cols='30'>
Smple text with mitake.
</textarea>
</body>
</html>
""");
}

private static BrowserView view;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ public void windowClosing(WindowEvent e) {
frame.setVisible(true);
});

browser.mainFrame().ifPresent(mainFrame -> mainFrame.loadHtml("<textarea></textarea>"));
browser.navigation().loadHtml("<textarea></textarea>");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,15 @@ public void windowClosing(WindowEvent e) {
frame.setVisible(true);
});

browser.mainFrame().ifPresent(mainFrame ->
mainFrame.loadHtml("<button onclick=\"clicked()\">click holding shift</button>" +
"<script>function clicked() {alert('clicked');}</script>"));
browser.navigation().loadHtml("""
<button onclick="clicked()">
Click holding shift
</button>
<script>
function clicked() {
alert('clicked');
}
</script>
""");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import androidx.compose.ui.window.singleWindowApplication
import com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly
import com.teamdev.jxbrowser.browser.Browser
import com.teamdev.jxbrowser.dsl.Engine
import com.teamdev.jxbrowser.dsl.browser.mainFrame
import com.teamdev.jxbrowser.dsl.browser.navigation
import com.teamdev.jxbrowser.dsl.subscribe
import com.teamdev.jxbrowser.dsl.ui.event.KeyPressed
Expand Down Expand Up @@ -60,7 +59,7 @@ fun main() {
private fun Browser.loadHtmlAndWait(html: String) {
val latch = CountDownLatch(1)
navigation.subscribe<FrameLoadFinished> { latch.countDown() }
mainFrame?.loadHtml(html)
navigation.loadHtml(html)
awaitUninterruptibly(latch)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import androidx.compose.ui.window.singleWindowApplication
import com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly
import com.teamdev.jxbrowser.browser.Browser
import com.teamdev.jxbrowser.dsl.Engine
import com.teamdev.jxbrowser.dsl.browser.mainFrame
import com.teamdev.jxbrowser.dsl.browser.navigation
import com.teamdev.jxbrowser.dsl.subscribe
import com.teamdev.jxbrowser.dsl.ui.Point
Expand Down Expand Up @@ -87,7 +86,7 @@ private fun Browser.dispatchMouseEvent() {
private fun Browser.loadHtmlAndWait() {
val latch = CountDownLatch(1)
navigation.subscribe<FrameLoadFinished> { latch.countDown() }
mainFrame?.loadHtml(ONCONTEXTMENU_CALLBACK)
navigation.loadHtml(ONCONTEXTMENU_CALLBACK)
awaitUninterruptibly(latch)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package com.teamdev.jxbrowser.examples
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.window.singleWindowApplication
import com.teamdev.jxbrowser.dsl.Engine
import com.teamdev.jxbrowser.dsl.browser.mainFrame
import com.teamdev.jxbrowser.dsl.browser.navigation
import com.teamdev.jxbrowser.dsl.dom.documentElement
import com.teamdev.jxbrowser.dsl.dom.getByName
Expand All @@ -47,7 +46,7 @@ fun main() {
BrowserView(browser)
LaunchedEffect(Unit) {
browser.navigation.fillFormOnLoadFinished()
browser.mainFrame?.loadHtml(HTML_FORM)
browser.navigation.loadHtml(HTML_FORM)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,38 @@

package com.teamdev.jxbrowser.examples

import com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly
import com.teamdev.jxbrowser.browser.Browser
import com.teamdev.jxbrowser.dsl.Engine
import com.teamdev.jxbrowser.dsl.browser.mainFrame
import com.teamdev.jxbrowser.dsl.browser.navigation
import com.teamdev.jxbrowser.dsl.dom.documentElement
import com.teamdev.jxbrowser.dsl.dom.findById
import com.teamdev.jxbrowser.dsl.frame.document
import com.teamdev.jxbrowser.dsl.subscribe
import com.teamdev.jxbrowser.engine.RenderingMode
import com.teamdev.jxbrowser.navigation.event.FrameLoadFinished
import java.util.concurrent.CountDownLatch

/**
* This example demonstrates how to obtain the list of existing attributes
* of a specified HTML element.
*/
fun main(): Unit = Engine(RenderingMode.OFF_SCREEN).use { engine ->
val browser = engine.newBrowser()
val mainFrame = browser.mainFrame?.also { it.loadHtml(HTML_LINK) }
val document = mainFrame?.document?.documentElement
browser.loadHtmlAndWait(HTML_LINK)
val document = browser.mainFrame?.document?.documentElement
val link = document?.findById("link")!!
link.attributes().asMap().forEach(::println)
}

private fun Browser.loadHtmlAndWait(html: String) {
val latch = CountDownLatch(1)
navigation.subscribe<FrameLoadFinished> { latch.countDown() }
navigation.loadHtml(html)
awaitUninterruptibly(latch)
}

private val HTML_LINK = """
<html lang="en">
<body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fun main() {
private fun Browser.loadHtmlAndWait(html: String) {
val latch = CountDownLatch(1)
navigation.subscribe<FrameLoadFinished> { latch.countDown() }
mainFrame?.loadHtml(html)
navigation.loadHtml(html)
awaitUninterruptibly(latch)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fun main() {
private fun Browser.loadHtmlAndWait(html: String) {
val latch = CountDownLatch(1)
navigation.subscribe<FrameLoadFinished> { latch.countDown() }
mainFrame?.loadHtml(html)
navigation.loadHtml(html)
awaitUninterruptibly(latch)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fun main() {
singleWindowApplication(title = "DOM query selector") {
BrowserView(browser)
LaunchedEffect(Unit) {
browser.mainFrame?.loadHtml(HTML_PARAGRAPHS)
browser.navigation.loadHtml(HTML_PARAGRAPHS)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fun main() {
select.options[2].select() // Selects "Opel".
}

browser.mainFrame?.loadHtml(
browser.navigation.loadHtml(
"""
<html lang="en">
<body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package com.teamdev.jxbrowser.examples
import androidx.compose.ui.window.singleWindowApplication
import com.teamdev.jxbrowser.browser.callback.OpenFileCallback
import com.teamdev.jxbrowser.dsl.Engine
import com.teamdev.jxbrowser.dsl.browser.mainFrame
import com.teamdev.jxbrowser.dsl.browser.navigation
import com.teamdev.jxbrowser.dsl.register
import com.teamdev.jxbrowser.engine.RenderingMode
import com.teamdev.jxbrowser.view.compose.BrowserView
Expand All @@ -42,7 +42,7 @@ fun main() {
tell.open(Path("file.txt"))
})

browser.mainFrame?.loadHtml(
browser.navigation.loadHtml(
"""
Please specify a file, or a set of files:<br>
<input type='file' name='datafile' size='40'>
Expand Down
Loading