use of com.teamdev.jxbrowser.view.swing.BrowserView 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.view.swing.BrowserView 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.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.
the class LoadHtml 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("Load HTML");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.mainFrame().ifPresent(mainFrame -> {
mainFrame.loadHtml("<html><body><h1>Hello there!</h1></body></html>");
});
}
use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.
the class LoadHtmlThroughInterceptRequest method main.
public static void main(String[] args) {
InterceptUrlRequestCallback interceptCallback = params -> {
if (params.urlRequest().url().endsWith("?load-html")) {
byte[] bytes = "<html><body>Hello!</body></html>".getBytes();
UrlRequestJob job = params.newUrlRequestJob(UrlRequestJob.Options.newBuilder(HttpStatus.OK).addHttpHeader(HttpHeader.of("Content-Type", "text/html")).build());
job.write(bytes);
job.complete();
return InterceptUrlRequestCallback.Response.intercept(job);
}
return InterceptUrlRequestCallback.Response.proceed();
};
Engine engine = Engine.newInstance(EngineOptions.newBuilder(HARDWARE_ACCELERATED).addScheme(Scheme.HTTP, interceptCallback).build());
Browser browser = engine.newBrowser();
SwingUtilities.invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("Load Local Files");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.navigation().loadUrl("http://localhost?load-html");
}
use of com.teamdev.jxbrowser.view.swing.BrowserView in project JxBrowser-Examples by TeamDev-IP.
the class CustomProtocol method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(EngineOptions.newBuilder(HARDWARE_ACCELERATED).addScheme(Scheme.of(PROTOCOL), new InterceptCustomSchemeCallback()).build());
Browser browser = engine.newBrowser();
invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("Custom Protocol Handler");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.navigation().loadUrl(PROTOCOL + "://hello");
}
Aggregations