Large language models open new workflows for web data extraction—summarization, classification, entity extraction, translation, and RAG ingestion.

In Java, LangChain4j provides type-safe APIs for prompts, structured outputs, and tool calling. The missing half is turning JavaScript-heavy modern web pages into clean, rendered text and screenshots that an LLM can reliably process.

Why HTTP Clients Fall Short 

Plain HTTP fetchers (such as UrlDocumentLoader) only retrieve the initial HTML shell. Modern web apps render titles, lists, and article content asynchronously via JavaScript or require scrolling and interaction.

Using a real Chromium browser via Fuzio executes page scripts normally inside the same Java process lifecycle without external browser drivers.

Setup 

Built with Fuzio 2026.5.0, LangChain4j 1.18.1, and JDK 17+:

plugins {
    java
    application
    id("tech.fuzio.gradle") version "1.0.0"
}

fuzio {
    version = "2026.5.0"
}

dependencies {
    implementation(fuzio.currentPlatform)

    implementation("dev.langchain4j:langchain4j:1.18.1")
    implementation("dev.langchain4j:langchain4j-open-ai:1.18.1")
}

Step 1: Start Fuzio 

Reuse a single Engine and Browser across sequential page fetches:

engine = Engine.newInstance(
        EngineOptions.newBuilder(HARDWARE_ACCELERATED)
                .enableIncognito()
                .timeZone(ZoneId.of("Asia/Shanghai"))
                .build());

engine.network().acceptLanguage("zh-CN,zh;q=0.9,en;q=0.8");

browser = engine.newBrowser();
browser.resize(1440, 900);

Step 2: Load the Page and Wait for Stability 

browser.navigation().loadUrlAndWait(url, Duration.ofSeconds(45));

Poll document.body.innerText.length until two consecutive reads match:

void waitUntilTextStable() {
    Frame frame = mainFrame();
    double previous = -1;
    for (int i = 0; i < 20; i++) {
        double length = frame.executeJavaScript("document.body.innerText.length");
        if (length == previous) {
            return;
        }
        previous = length;
        sleep(500);
    }
}

Step 3: Convert the Page into a LangChain4j Document 

Frame frame  = browser.mainFrame().orElseThrow();
String url   = frame.executeJavaScript("document.location.href");
String title = frame.executeJavaScript("document.title");
String body  = frame.executeJavaScript("document.body.innerText");

Metadata metadata = Metadata.from(Document.URL, url);
metadata.put("title", title);
metadata.put("fetched_at", Instant.now().toString());
Document page = Document.from(body, metadata);
  • innerText reflects visible rendered text and skips display: none elements.
  • Document plugs directly into LangChain4j’s DocumentSplitter and EmbeddingStoreIngestor.

Handling Images 

Preserve <img> alt descriptions inline before extracting innerText:

frame.executeJavaScript("""
        document.querySelectorAll('img').forEach(img => {
            const alt = (img.getAttribute('alt') || '').trim();
            const marker = document.createElement('span');
            marker.textContent = alt ? '\\n[Image: ' + alt + ']\\n' : '\\n[Image]\\n';
            img.replaceWith(marker);
        });
        """);

When charts or infographics carry essential meaning, capture a full-page PNG and pass it to a multimodal model:

double pageWidth = frame.executeJavaScript(
        "Math.max(document.body.scrollWidth, document.documentElement.scrollWidth)");
double pageHeight = frame.executeJavaScript(
        "Math.max(document.body.scrollHeight, document.documentElement.scrollHeight)");
browser.resize((int) pageWidth, (int) pageHeight);

Thread.sleep(2000);

var bitmap = browser.bitmap();
var image = BitmapImage.toToolkit(bitmap);

var output = new ByteArrayOutputStream();
ImageIO.write(image, "PNG", output);
String base64Png = Base64.getEncoder().encodeToString(output.toByteArray());
UserMessage message = UserMessage.from(
        TextContent.from("Summarize what the chart in this screenshot shows."),
        ImageContent.from(base64Png, "image/png"));

String answer = model.chat(message).aiMessage().text();

Step 4: Structured Extraction with LangChain4j 

Define a Java record as the extraction contract:

public record ArticleSummary(
        @Description("Chinese title of the page") String titleZh,
        @Description("English translation of the title") String titleEn,
        @Description("Chinese summary within 150 characters") String summaryZh,
        @Description("Corresponding English summary") String summaryEn,
        @Description("2 to 4 topic categories") List<String> topics) {
}
public interface ArticleAnalyzer {

    @SystemMessage("""
            You are a precise web content extraction assistant.
            Answer strictly from the provided page text and leave unknown fields empty.
            """)
    @UserMessage("""
            Extract information from the following web page.

            URL: {{url}}
            Content:
            {{content}}
            """)
    ArticleSummary analyze(@V("url") String url, @V("content") String content);
}

Enable JSON Schema enforcement on the model:

ChatModel model = OpenAiChatModel.builder()
        .apiKey(System.getenv("OPENAI_API_KEY"))
        .modelName("gpt-4o-mini")
        .supportedCapabilities(RESPONSE_FORMAT_JSON_SCHEMA)
        .strictJsonSchema(true)
        .temperature(0.0)
        .timeout(Duration.ofSeconds(120))
        .build();
ArticleAnalyzer analyzer = AiServices.create(ArticleAnalyzer.class, model);
ArticleSummary summary = analyzer.analyze(page.metadata().getString(Document.URL), page.text());

For OpenAI-compatible endpoints that only support json_object (such as DeepSeek), switch to responseFormat("json_object") and describe the fields in the prompt.

Handling Pagination and Rate Limits 

Scroll to Trigger Lazy Loading 

static final String PAGE_HEIGHT =
        "Math.max(document.body.scrollHeight, document.documentElement.scrollHeight)";

void scrollToBottom(int maxRounds) {
    Frame frame = mainFrame();
    double lastHeight = -1;
    for (int i = 0; i < maxRounds; i++) {
        double height = frame.executeJavaScript(PAGE_HEIGHT);
        if (height == lastHeight) {
            return;
        }
        lastHeight = height;
        frame.executeJavaScript("window.scrollTo(0, " + PAGE_HEIGHT + ")");
        sleep(800);
    }
}

Retries with Polite Backoff 

private void loadWithRetry(String url) {
    for (int attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
        try {
            sleep(500L * attempt);
            browser.navigation().loadUrlAndWait(url, LOAD_TIMEOUT);
            return;
        } catch (NavigationException e) {
            boolean retryable = e.netError() == NetError.ABORTED;
            if (!retryable || attempt == MAX_ATTEMPTS) {
                throw e;
            }
        }
    }
}

Always respect robots.txt, site terms of service, request rate limits, and applicable data-protection laws.

Giving the Model Browser Control via @Tool 

You can also let the LLM drive navigation, reading, clicking, and scrolling through LangChain4j @Tool methods backed by a shared Browser:

public final class WebTools {

    private final FuzioDocumentLoader loader;

    @Tool("Open the given URL, wait for JavaScript rendering, and return the title and opening text.")
    public String openPage(
            @P("Full URL starting with http:// or https://") String url) { /* … */ }

    @Tool("Read the full rendered text of the current page.")
    public String readPage() { /* … */ }

    @Tool("Find and click a link or button matching the given text.")
    public String clickText(
            @P("Visible link or button text") String text) { /* … */ }

    @Tool("Scroll down to trigger lazy loading and return newly loaded content.")
    public String scrollForMore() { /* … */ }
}

Conclusion 

Separating responsibilities keeps dynamic web extraction clean: Fuzio renders JavaScript-heavy pages reliably, LangChain4j handles typed schemas and @Tool orchestration, and the LLM structures the extracted content for downstream search or RAG pipelines.

Further Reading 

Add a Chromium-based browser engine to your Java desktop app with Fuzio.

Try for free