Skip to content

Support for SSE? #395

@spinscale

Description

@spinscale

first, thanks for HTMLUnit, first time I am using it and it is really nice.

I tried to test a javalin web app with SSE (server side events), plus htmx on the client side (you tweeted about it a few weeks ago, see https://twitter.com/HtmlUnit/status/1447250140423770122).

So, here is my setup:

    private final Javalin app;
    private final ConcurrentLinkedQueue<SseClient> clients = new ConcurrentLinkedQueue<>();

    app.sse("sse-events", client -> {
        clients.add(client);
        client.onClose(() -> clients.remove(client));
    });
<div class="container mx-auto px-40 pb-10">
    <div hx-sse="connect:/sse-events">
        <div hx-sse="swap:box-update">
            <div class="flex pl-4 pr-4 pt-4 pb-4 mt-4 mb-4" id="sse-element">
                <div class="flex-grow content text-text">&nbsp;</div>
            </div>
        </div>
    </div>
</div>

Test looks like this

try (final WebClient webClient = new WebClient()) {
    webClient.getOptions().setRedirectEnabled(true);
    webClient.getOptions().setCssEnabled(false);
    webClient.setAjaxController(new NicelyResynchronizingAjaxController());
    webClient.setJavaScriptErrorListener(new DefaultJavaScriptErrorListener());
    final HtmlPage mainPage = webClient.getPage("http://localhost:7000/");
    ...
}

Running that test in debug mode, leads to the sse-events endpoint not being called, despite part of the HTML that the mainpage returns.

Hope this helps as a start, otherwise I can try to provide a minimal fully reproducible example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions