Search in sources :

Example 21 with Browser

use of com.teamdev.jxbrowser.browser.Browser in project JxBrowser-Examples by TeamDev-IP.

the class WebSocket 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("Web Socket");
        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.websocket.org/echo.html");
}
Also used : JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 22 with Browser

use of com.teamdev.jxbrowser.browser.Browser 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"));
    }
}
Also used : Bitmap(com.teamdev.jxbrowser.ui.Bitmap) BufferedImage(java.awt.image.BufferedImage) BitmapImage(com.teamdev.jxbrowser.view.javafx.graphics.BitmapImage) Image(javafx.scene.image.Image) File(java.io.File) Engine(com.teamdev.jxbrowser.engine.Engine) BufferedImage(java.awt.image.BufferedImage) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 23 with Browser

use of com.teamdev.jxbrowser.browser.Browser 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");
}
Also used : JFrame(javax.swing.JFrame) Network(com.teamdev.jxbrowser.net.Network) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 24 with Browser

use of com.teamdev.jxbrowser.browser.Browser 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");
}
Also used : JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Example 25 with Browser

use of com.teamdev.jxbrowser.browser.Browser 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')");
        });
    }
}
Also used : JsObject(com.teamdev.jxbrowser.js.JsObject) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Aggregations

Browser (com.teamdev.jxbrowser.browser.Browser)73 Engine (com.teamdev.jxbrowser.engine.Engine)70 JFrame (javax.swing.JFrame)51 BrowserView (com.teamdev.jxbrowser.view.swing.BrowserView)47 BorderLayout (java.awt.BorderLayout)8 HARDWARE_ACCELERATED (com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED)7 SwingUtilities (javax.swing.SwingUtilities)7 WindowConstants (javax.swing.WindowConstants)7 EngineOptions (com.teamdev.jxbrowser.engine.EngineOptions)6 Document (com.teamdev.jxbrowser.dom.Document)5 Frame (com.teamdev.jxbrowser.frame.Frame)5 JsObject (com.teamdev.jxbrowser.js.JsObject)5 FrameLoadFinished (com.teamdev.jxbrowser.navigation.event.FrameLoadFinished)5 BrowserView (com.teamdev.jxbrowser.view.javafx.BrowserView)5 WindowAdapter (java.awt.event.WindowAdapter)5 WindowEvent (java.awt.event.WindowEvent)5 Scene (javafx.scene.Scene)5 BrowserView (com.teamdev.jxbrowser.view.swt.BrowserView)4 OFF_SCREEN (com.teamdev.jxbrowser.engine.RenderingMode.OFF_SCREEN)3 Navigation (com.teamdev.jxbrowser.navigation.Navigation)3