Note: Advice in this article will only work for JxBrowser 6. See the corresponding article for JxBrowser 7 here.

To get a string that represents HTML of loaded web page use Browser.getHTML() method. You must call this method only when web page is loaded completely. Otherwise you might receive incomplete HTML or empty string. The following code demonstrates how to wait until web page is loaded completely and get its HTML: 

import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;

import javax.swing.*;
import java.awt.*;

 * This sample demonstrates how to load custom HTML string into
 * Browser component and display it.
public class GetHTMLSample {
    public static void main(String[] args) {
        Browser browser = new Browser();
        BrowserView browserView = new BrowserView(browser);

        JFrame frame = new JFrame();
        frame.add(browserView, BorderLayout.CENTER);
        frame.setSize(700, 500);

        browser.addLoadListener(new LoadAdapter() {
            public void onFinishLoadingFrame(FinishLoadingEvent event) {
                if (event.isMainFrame()) {
                    System.out.println("HTML = " + event.getBrowser().getHTML());