Class Nordstjernen

java.lang.Object
org.nordstjernen.Nordstjernen

public final class Nordstjernen extends Object
Entry point for embedding the Nordstjernen browser engine from Java.

This is a thin JNI veneer over the C embedding API (libnordstjernen.h). The engine relies on a single GLib main context and is not safe for concurrent use across threads; drive it from one thread and treat Page instances as non-thread-safe. Always close() a page (it owns native memory); shutdown() releases process-wide engine state.


 try (Page page = Nordstjernen.open("https://example.com", 360, 600)) {
     System.out.println(page.title());
     page.renderToFile(Path.of("example.png"));
 }
 
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Default settle time (ms) for the one-shot convenience methods.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Initialize the engine (idempotent).
    static List<String>
    linksOf(String url, int viewportWidthCss)
    Open url, collect its links, and close.
    static Page
    open(String url, int viewportWidthCss, int settleMs)
    Fetch, parse, lay out and script url, returning a Page.
    static void
    saveScreenshot(String url, int viewportWidthCss, Path out)
    Open url, render the whole page to a PNG/PDF file, and close.
    screenshot(String url, int viewportWidthCss, double scale)
    Open url, render the whole page to an image, and close.
    static void
    Release process-wide engine state.
    static String
    textOf(String url, int viewportWidthCss)
    Open url, extract its text, and close.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_SETTLE_MS

      public static final int DEFAULT_SETTLE_MS
      Default settle time (ms) for the one-shot convenience methods.
      See Also:
  • Method Details

    • init

      public static void init()
      Initialize the engine (idempotent). Loads the native libraries on first call.
    • shutdown

      public static void shutdown()
      Release process-wide engine state. After this, init() re-initializes.
    • open

      public static Page open(String url, int viewportWidthCss, int settleMs)
      Fetch, parse, lay out and script url, returning a Page.
      Parameters:
      url - absolute URL, about: page, data: URL or local path
      viewportWidthCss - layout viewport width in CSS pixels (e.g. 360 for a phone)
      settleMs - milliseconds to let scripts/animations settle before layout
      Returns:
      an open page; the caller must Page.close() it
      Throws:
      NordstjernenException - if the page cannot be opened
    • screenshot

      public static BufferedImage screenshot(String url, int viewportWidthCss, double scale)
      Open url, render the whole page to an image, and close.
    • saveScreenshot

      public static void saveScreenshot(String url, int viewportWidthCss, Path out)
      Open url, render the whole page to a PNG/PDF file, and close.
    • textOf

      public static String textOf(String url, int viewportWidthCss)
      Open url, extract its text, and close.
    • linksOf

      public static List<String> linksOf(String url, int viewportWidthCss)
      Open url, collect its links, and close.