The WebAPI package

3 min read Original article ↗

The SnapKit WebAPI package provides a set of WebAPI wrapper classes that are a bridge to the browser WebAPIs. This allows Java developers to directly manipulate the DOM when running in the browser. SnapKit, as full UI toolkit like Swing/JavaFX, uses this package in the browser to get native graphics acceleration, WebGL 3D rendering, system clipboard/drag-and-drop and more.

Here are some demos of Java WebAPI programming, running live in a Java browser IDE (SnapCode) that is itself running on WebAPI:

DomSamples

WebAPI Demos in SnapCode

Why Java needs WebAPI

Java UI development is disappearing. Both Swing and JavaFX still have attractive development models, but deployment is mostly limited to the desktop. Increasingly, platform vendors and users are less enthusiastic about installing desktop applications unless the benefits are overwhelming.

To make Java UI development attractive again, Java must support deployment in the browser, support integration with the browser and support more browser standards and paradigms. The ideal modern Java UI framework should include these features:

- Run in browser and desktop
- Support modern graphics, audio, video, animation and 3D
- Interoperable with other web technologies and services
- Leverage familiarity and ubiquity of browser programming
- Leverage skills most front-end developers have and want
- Not require years of development and excessive funding

If you accept any of that, then it follows that Java UI should fundamentally be built on WebAPI. There is no need to rewrite this vast functionality, WebAPIs are readily available everywhere: in every browser and on the desktop via Chrome packaging. Web APIs are the new "AWT" - and Java doesn't have to play an impossible game of catch up.

WebAPIs on the desktop

And to see a preliminary demo of SnapCode running on the desktop and using Chrome as the windowing, rendering and runtime, download jbang and run SnapCode with this simple command:

  • Desktop app: jbang snapcode@reportmill
SnapCode_JxBrowser

SnapCode running in Chrome on the Desktop

This uses the JxBrowser framework to easily interface with Chrome. [Edit: this link has been changed back to the conventional SnapCode (utilizing Swing), since our JxBrowser evaluation license ran out].

How to use

Since the WebAPI framework is a wrapper, it needs access to a real WebAPI implementation. In the browser, this can be done with CheerpJ. On the desktop, this can be done with the JxBrowser library. This project contains an adapter for each of those environments.

Use with CheerpJ in the browser

To run this library in the browser with CheerpJ:

- Include SnapKit gradle/maven dependency: "com.reportmill:snapkit:2025.12"
- Copy cjdom.js and cjdom.html from SnapKit repo to build/libs dir
- Run some http-server in that directory
- Go to http://localhost:8080/cjdom.html in your browser

Use with JxBrowser on the desktop

To use this library on the desktop with JxBrowser, contact us for details.

You will also need to get a JxBrowser key from the JxBrowser people by clicking on the "Try for free" link.