Skip to content

The WebAPI package

Jeff Martin edited this page Dec 3, 2025 · 4 revisions

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 itself uses this package in the browser to get native graphics acceleration, 3D and more.

Web APIs go beyond Swing and JavaFX

To get Java back in the UI game the value must be high and costs low. The ideal modern Java UI framework should include these features:

- Run in browser and desktop
- Leverage familiarity and ubiquity of browser programming
- Support modern graphics, audio, video, animation and 3D
- Interoperable with other end user technologies and services
- 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 Web API. There is no need to rewrite this vast functionality, Web APIs 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.

Here are some demos of Java Web API in action, running in a Java IDE (SnapCode) that is itself running on WebAPI:

DomSamples

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 snapcodejx@reportmill
SnapCode_JxBrowser

This uses the JxBrowser framework to easily interface with Chrome. There has only been about a week of development on this and our evaluation license runs out soon. But we hope to add polish and figure out a JxBrowser licensing solution once the project generates more interest.

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:

- ./gradlew build
- Copy cjdom.js and cjdom.html 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:

- Edit build.gradle
- Uncomment jxbrowser dependency for platform
    - This is one of: mac, win, mac-arm, win-arm or linux

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

Clone this wiki locally