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");
}
Aggregations