Browser API Integration

Access clipboard, geolocation, notifications, and more from Java—no JavaScript required.

Oorian wraps 18 browser JavaScript APIs with type-safe Java classes. Each API follows a consistent pattern: call a static method from your Java code, and the framework handles the JavaScript communication automatically. Results arrive as typed events delivered to your Java listener.

GeolocationApi

User location

ClipboardApi

Copy & paste

NotificationApi

System alerts

StorageApi

Local storage

FullscreenApi

Fullscreen mode

ScreenApi

Screen info

WindowApi

Window control

NavigationApi

Page navigation

NetworkApi

Online status

MediaDevicesApi

Camera & mic

PermissionsApi

Permission checks

ShareApi

Native sharing

SpeechApi

Voice input

SelectionApi

Text selection

TimerApi

Delayed execution

VibrationApi

Haptic feedback

VisibilityApi

Tab visibility

WakeLockApi

Prevent sleep

Every API provides convenience methods that use the current thread's page context, plus explicit overloads that accept an HtmlPage parameter for use in worker threads or shared services.

Geolocation

GeolocationApi wraps the browser's navigator.geolocation API. Request the user's current position or track changes over time. The browser prompts for permission, retrieves the location, and delivers the result to your Java listener as a typed GeolocationEvent.

Java
@Page("/location-demo")
public class LocationPage extends HtmlPage implements GeolocationListener
{
    private P statusLabel;
    private P coordinatesLabel;
    private Button locationBtn;

    @Override
    protected void createBody(Body body)
    {
        statusLabel = new P("Click the button to get your location.");
        body.addElement(statusLabel);

        coordinatesLabel = new P();
        coordinatesLabel.setFontFamily("monospace");
        body.addElement(coordinatesLabel);

        locationBtn = new Button("Get My Location");
        locationBtn.registerListener(this, MouseClickedEvent.class);
        locationBtn.registerListener(this, GeolocationEvent.class);
        locationBtn.registerListener(this, GeolocationErrorEvent.class);
        body.addElement(locationBtn);
    }

    @Override
    public void onEvent(MouseClickedEvent event)
    {
        statusLabel.setText("Requesting location...");
        GeolocationApi.getCurrentPosition(locationBtn);
    }

    @Override
    public void onEvent(GeolocationEvent event)
    {
        statusLabel.setText("Location received!");
        coordinatesLabel.setText(String.format(
            "Lat: %.6f, Lng: %.6f (accuracy: %.0fm)",
            event.getLatitude(),
            event.getLongitude(),
            event.getAccuracy()));
    }

    @Override
    public void onEvent(GeolocationErrorEvent event)
    {
        statusLabel.setText("Error: " + event.getMessage());
    }
}

Continuous Tracking

Use watchPosition() to receive continuous location updates. The browser delivers new coordinates whenever the user moves. Call clearWatch() with the returned ID to stop tracking.

Java
// Start tracking — events arrive via GeolocationListener
String watchId = GeolocationApi.watchPosition(locationBtn);

// Stop tracking
GeolocationApi.clearWatch(watchId);

How It Works

  1. Your Java code calls GeolocationApi.getCurrentPosition()
  2. Oorian sends a command to the browser to invoke navigator.geolocation
  3. The browser prompts the user for permission and retrieves location
  4. The result is sent back to the server and delivered to your GeolocationListener

Clipboard

ClipboardApi wraps the browser's Clipboard API. Write text to the clipboard with a single method call, or read clipboard contents asynchronously with a listener for the result.

Writing to Clipboard

Java
// Copy text to clipboard (one-liner)
ClipboardApi.writeText("Text to copy");

// Copy from a page context
ClipboardApi.writeText(this, generatedCode);

writeText() sends a command to the browser that calls navigator.clipboard.writeText(). No listener needed for write operations.

Reading from Clipboard

Java
// Read clipboard (async, result via listener)
ClipboardApi.readText(pasteBtn);

// Handle the result
@Override
public void onEvent(ClipboardReadEvent event)
{
    String text = event.getText();
    processClipboardContent(text);
}

Reading requires user permission. The browser prompts the user, then delivers the result to your ClipboardListener.

Notifications

NotificationApi shows native browser notifications from your Java code. Customize the title, body, and icon. Listen for click and close events to respond when the user interacts with the notification.

Java
// Request permission first
NotificationApi.requestPermission(notifyBtn);

// Show a simple notification
NotificationApi.show(notifyBtn, "Task Complete",
    "Your report has been generated.");

// Show with options
NotificationOptions options = new NotificationOptions();
options.setIcon("/images/notification-icon.png");
options.setTag("new-messages");
NotificationApi.show(notifyBtn, "New Messages", options);

// Close all active notifications
NotificationApi.closeAll();

Implement NotificationListener to receive NotificationClickEvent when the user clicks on a notification, or NotificationCloseEvent when it is dismissed.

Web Storage

StorageApi provides access to both localStorage (persists across sessions) and sessionStorage (cleared when the tab closes). Write operations are synchronous; read operations are asynchronous and deliver results to your StorageListener.

localStorage

Java
// Store a value (persists across sessions)
StorageApi.setLocalItem("theme", "dark");
StorageApi.setLocalItem("language", "en");

// Retrieve a value (async, result via listener)
StorageApi.getLocalItem("theme", themeLabel);

// Remove a single item
StorageApi.removeLocalItem("theme");

// Clear all localStorage
StorageApi.clearLocalStorage();

sessionStorage

Java
// Store a value (cleared when tab closes)
StorageApi.setSessionItem("wizardStep", "3");
StorageApi.setSessionItem("formDraft", jsonData);

// Retrieve a value (async, result via listener)
StorageApi.getSessionItem("wizardStep", stepLabel);

// Remove a single item
StorageApi.removeSessionItem("wizardStep");

// Clear all sessionStorage
StorageApi.clearSessionStorage();

Implement StorageListener to receive StorageEvent when a value is retrieved. The event contains the key and value as strings.

Benefits

No JavaScript Required

Access browser APIs through clean Java methods. The framework generates and manages all JavaScript communication behind the scenes.

Consistent Listener Pattern

Every async API follows the same pattern: call a static method, implement a listener interface, receive a typed event. Learn the pattern once and it applies to all 18 APIs.

Type-Safe Results

Geolocation returns GeolocationPosition with getLatitude() and getLongitude(). Clipboard returns ClipboardReadEvent with getText(). No JSON parsing or string manipulation required.

Automatic Communication

Results from browser APIs are sent back to your Java code via the page's communication channel (AJAX, SSE, or WebSocket). The framework handles serialization and delivery.

Thread-Safe Convenience

Each API provides static convenience methods that resolve the current page from the thread context, plus explicit overloads that accept an HtmlPage for use in worker threads.

Cross-Browser Compatibility

The framework handles browser differences and permission models. Your Java code works consistently across all modern browsers.