Class RemoteBrowser

java.lang.Object
org.nordstjernen.RemoteBrowser
All Implemented Interfaces:
AutoCloseable

public final class RemoteBrowser extends Object implements AutoCloseable
A long-lived browser backed by a single nordstjernen-renderer process. Unlike RemotePage (one page, then the renderer exits), this keeps the renderer alive so an interactive shell can navigate, scroll, render viewports, and follow links — the model the GTK shell uses. No native engine is loaded into the JVM.

Not thread-safe; drive one instance from a single thread (or serialise).

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Result of a find-in-page query: match count, the current 1-based index, and where to scroll.
    static final class 
    Result of a render: the image plus any side-channel the page requested.
    static final class 
    A hover probe: whether the frame changed, the link under the point, and the CSS cursor.
    static final class 
    Result of a key event: any navigation it triggered, and whether the page consumed it.
    static final class 
    A clickable media element resolved at a point: its URL, whether it is video, and if it streams.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
    Maximum framebuffer the renderer is asked to allocate.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    Drain any buffered console.* output the page produced, or null.
    eval(String src)
    Evaluate JavaScript in the page and return its result rendered as text.
    boolean
    export(String path)
    Render the whole page to path (a .pdf → PDF, else PNG); true on success.
    The current page's favicon as an image, or null if it has none.
    find(String query, boolean caseSensitive, int direction, int fromY)
    Find query in the page.
    hover(int x, int y)
    Probe the point under the pointer: moves the engine's hover state (firing :hover / mouseover), and reports the link there and the CSS cursor name so the shell can mirror the GTK status bar and pointer shape.
    key(int kind, String key, String code, int keycode, int mods)
    Forward a key event to the focused element.
    linkAt(int x, int y)
    The link URL at a document-coordinate point, or null.
    mediaAt(int x, int y)
    The media element (audio/video URL) at a document-coordinate point, or null.
    boolean
    navigate(String url, int viewportWidthCss, int viewportHeightCss, int settleMs)
    Navigate to url; returns false if the page failed to open.
    int
     
    int
     
    A client-side redirect (meta refresh or JS location) that fired while the just-opened page settled, or null.
    press(int x, int y, int mods)
    Press at a document-coordinate point (then call release()).
    Release a pending press; returns a navigation URL if the click followed a link.
    render(int scrollX, int scrollY, int width, int height, double scale)
    Render a viewport region (document coordinates via scroll) to an image.
    void
    resolveWebgl(String origin, boolean allow)
    Allow or block WebGL for origin for the rest of the session.
    void
    Replace a dead renderer with a fresh process.
    select(int kind, int x, int y)
    Drive a text selection.
    void
    setViewport(int widthCss, int heightCss)
    Tell the engine the viewport changed (re-lays out, fires resize).
     
    url()
     

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • RemoteBrowser

      public RemoteBrowser()
  • Method Details

    • pendingNav

      public String pendingNav()
      A client-side redirect (meta refresh or JS location) that fired while the just-opened page settled, or null. Follow it to land on the real destination — e.g. a duckduckgo.com/l/?uddg=… result link.
    • setViewport

      public void setViewport(int widthCss, int heightCss)
      Tell the engine the viewport changed (re-lays out, fires resize).
    • render

      public RemoteBrowser.Frame render(int scrollX, int scrollY, int width, int height, double scale)
      Render a viewport region (document coordinates via scroll) to an image.
    • linkAt

      public String linkAt(int x, int y)
      The link URL at a document-coordinate point, or null.
    • hover

      public RemoteBrowser.Hover hover(int x, int y)
      Probe the point under the pointer: moves the engine's hover state (firing :hover / mouseover), and reports the link there and the CSS cursor name so the shell can mirror the GTK status bar and pointer shape.
    • select

      public String select(int kind, int x, int y)
      Drive a text selection. kind is 0 to anchor a new selection at the point, 1 to extend it, 3 to select the whole document, and 4 to return the currently selected text (the copy path). Returns the selected text for kind == 4, otherwise null.
    • find

      public RemoteBrowser.Find find(String query, boolean caseSensitive, int direction, int fromY)
      Find query in the page. direction is 0 to (re)search from fromY, 1 for the next match, 2 for the previous. Returns the match count, the current match index, and the document Y to scroll the match into view.
    • eval

      public String eval(String src)
      Evaluate JavaScript in the page and return its result rendered as text.
    • consoleDrain

      public String consoleDrain()
      Drain any buffered console.* output the page produced, or null.
    • mediaAt

      public RemoteBrowser.Media mediaAt(int x, int y)
      The media element (audio/video URL) at a document-coordinate point, or null.
    • export

      public boolean export(String path)
      Render the whole page to path (a .pdf → PDF, else PNG); true on success.
    • resolveWebgl

      public void resolveWebgl(String origin, boolean allow)
      Allow or block WebGL for origin for the rest of the session.
    • favicon

      public BufferedImage favicon()
      The current page's favicon as an image, or null if it has none.
    • press

      public String press(int x, int y, int mods)
      Press at a document-coordinate point (then call release()).
    • release

      public String release()
      Release a pending press; returns a navigation URL if the click followed a link.
    • key

      public RemoteBrowser.Key key(int kind, String key, String code, int keycode, int mods)
      Forward a key event to the focused element. kind is 0 for keydown, 1 for keyup, 2 to insert key as text, 3 for keypress. key and code are the KeyboardEvent.key/.code values.
    • title

      public String title()
    • url

      public String url()
    • pageWidth

      public int pageWidth()
    • pageHeight

      public int pageHeight()
    • restart

      public void restart()
      Replace a dead renderer with a fresh process. Call after a request throws (the child crashed or wedged); the caller must then re-navigate, since the new process starts with no page loaded.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable