use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.
the class BitmapToJavaFxImage method main.
public static void main(String[] args) throws IOException {
try (Engine engine = Engine.newInstance(OFF_SCREEN)) {
Browser browser = engine.newBrowser();
// Resize browser to the required dimension
browser.resize(1024, 768);
// Load the required web page and wait until it is loaded completely
browser.navigation().loadUrlAndWait("https://www.google.com");
Bitmap bitmap = browser.bitmap();
// Convert the bitmap to javafx.scene.image.Image
Image image = BitmapImage.toToolkit(bitmap);
// Convert javafx.scene.image.Image to java.awt.image.BufferedImage
BufferedImage bufferedImage = SwingFXUtils.fromFXImage(image, null);
// Save the image to a PNG file
ImageIO.write(bufferedImage, "PNG", new File("bitmap.png"));
}
}
use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.
the class FilterCookies method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
Browser browser = engine.newBrowser();
SwingUtilities.invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("Filter Cookies");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
// Suppress/filter all the incoming and outgoing cookies.
Network networkService = engine.network();
networkService.set(CanSetCookieCallback.class, params -> {
System.out.println("Disallow accepting cookies for: " + params.url());
return CanSetCookieCallback.Response.cannot();
});
networkService.set(CanGetCookiesCallback.class, params -> {
System.out.println("Disallow sending cookies for: " + params.url());
return CanGetCookiesCallback.Response.cannot();
});
browser.navigation().loadUrl("https://www.google.com");
}
use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.
the class InterceptRequest method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(EngineOptions.newBuilder(OFF_SCREEN).addScheme(Scheme.HTTPS, new InterceptHttpsCallback()).build());
Browser browser = engine.newBrowser();
invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("Intercept Request");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.navigation().loadUrl("https://www.google.com");
}
use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.
the class JsAccessibleClass method main.
public static void main(String[] args) {
try (Engine engine = Engine.newInstance(OFF_SCREEN)) {
Browser browser = engine.newBrowser();
browser.mainFrame().ifPresent(frame -> {
JsObject jsObject = frame.executeJavaScript("window");
if (jsObject != null) {
// Inject Java object into JavaScript and associate it
// with the "window.java" JavaScript property.
jsObject.putProperty("java", new JavaObject());
}
// Call the public method of the injected Java object from JS.
frame.executeJavaScript("window.java.sayHelloTo('John')");
});
}
}
use of com.teamdev.jxbrowser.engine.Engine in project JxBrowser-Examples by TeamDev-IP.
the class JsFunctionCallback method main.
public static void main(String[] args) {
try (Engine engine = Engine.newInstance(OFF_SCREEN)) {
Browser browser = engine.newBrowser();
browser.mainFrame().ifPresent(frame -> {
JsObject jsObject = frame.executeJavaScript("window");
if (jsObject != null) {
// Inject JsFunctionCallback into JavaScript and associate it
// with the "window.sayHelloTo" JavaScript property.
jsObject.putProperty("sayHelloTo", (com.teamdev.jxbrowser.js.JsFunctionCallback) arguments -> "Hello, " + arguments[0]);
}
String greetings = frame.executeJavaScript("window.sayHelloTo('John')");
System.out.println(greetings);
});
}
}
Aggregations