Search in sources :

Example 1 with Network

use of com.teamdev.jxbrowser.net.Network 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)

Aggregations

Browser (com.teamdev.jxbrowser.browser.Browser)1 Engine (com.teamdev.jxbrowser.engine.Engine)1 Network (com.teamdev.jxbrowser.net.Network)1 BrowserView (com.teamdev.jxbrowser.view.swing.BrowserView)1 JFrame (javax.swing.JFrame)1