eBowser — Embedded Web Browser v0.1.0

eBowser is a lightweight, embeddable web browser engine for EmbeddedOS. Built from scratch in C/C++ with minimal dependencies, it provides HTML5 parsing, CSS styling, box-model layout, software rendering, and HTTP/HTTPS networking — all in a footprint suitable for resource-constrained embedded devices, kiosks, and IoT dashboards.

Headers: #include <ebowser/*.h> | License: MIT | Backends: SDL2, EoS native, WASM

Architecture Overview

Core Engine: Browser lifecycle, configuration, and embedding API.
HTML Parser: Tokenizer → DOM tree construction with error recovery.
CSS Engine: Stylesheet parsing, cascade, specificity, computed styles.
Layout Engine: Box model, block/inline flow, flexbox, text wrapping.
Rendering: Software rasterizer with SDL2 and EoS display backends.
Network: HTTP/1.1, HTTPS (TLS 1.2/1.3), cookies, connection pooling.
Input: Keyboard, mouse, and touch input abstraction with focus management.
Platform: Portable abstraction layer for SDL2, EoS native, and WebAssembly.

Quick Start
#include <ebowser/ebowser.h>

int main(void) {
    eb_config_t cfg = {
        .width = 1024, .height = 768,
        .title = "eBowser",
        .flags = EB_FLAG_RESIZABLE
    };
    eb_handle_t browser = eb_create(&cfg);
    eb_navigate(browser, "https://example.com");
    eb_run(browser);  // blocks until window closed
    eb_destroy(browser);
    return 0;
}

⚙ Core Engine

Browser lifecycle, configuration, and embedding API. Header: <ebowser/ebowser.h>

Configuration

eb_config_t

widthuint32_tInitial window width in pixels (default: 1024)
heightuint32_tInitial window height in pixels (default: 768)
titleconst char *Window title string
flagsuint32_tBitwise OR of EB_FLAG_* constants
user_agentconst char *Custom User-Agent string (NULL = default)
cache_size_mbuint32_tMax cache size in MB (default: 64)
home_urlconst char *Homepage URL (NULL = about:blank)
proxyconst char *HTTP proxy URL (NULL = direct)
Configuration Flags
EB_FLAG_RESIZABLE=0x01EB_FLAG_FULLSCREEN=0x02EB_FLAG_BORDERLESS=0x04EB_FLAG_NO_JS=0x08EB_FLAG_KIOSK=0x10EB_FLAG_HEADLESS=0x20EB_FLAG_HARDWARE_ACCEL=0x40

Lifecycle

eb_handle_t eb_create(const eb_config_t *config)

Create a new browser instance. Initializes the platform backend, rendering surface, and network stack.

Parameters
configconst eb_config_t *Browser configuration. Pass NULL for defaults (1024×768, resizable).
Returns

eb_handle_t browser handle, or EB_INVALID_HANDLE on failure.

Example
eb_config_t cfg = {
    .width = 800, .height = 600,
    .title = "My Embedded Browser",
    .flags = EB_FLAG_RESIZABLE | EB_FLAG_HARDWARE_ACCEL,
    .cache_size_mb = 32,
    .home_url = "https://example.com"
};
eb_handle_t browser = eb_create(&cfg);
if (browser == EB_INVALID_HANDLE) {
    fprintf(stderr, "Failed to create browser\n");
    return 1;
}
int eb_navigate(eb_handle_t browser, const char *url)

Navigate to a URL. Initiates DNS resolution, HTTP request, HTML parsing, layout, and rendering. Non-blocking — the page loads asynchronously.

Parameters
browsereb_handle_tBrowser handle.
urlconst char *URL to navigate to (http://, https://, file://, or about:).
Returns

0 on success, negative error code on failure.

Example
eb_navigate(browser, "https://example.com");
eb_navigate(browser, "file:///data/local.html");
eb_navigate(browser, "about:blank");
int eb_run(eb_handle_t browser)

Enter the main event loop. Processes input events, network I/O, layout updates, and rendering. Blocks until the browser window is closed or eb_stop() is called.

Returns

0 on clean exit.

int eb_step(eb_handle_t browser)

Process a single frame of the event loop. Use instead of eb_run() when embedding the browser in a custom event loop.

Returns

1 if running, 0 if exit was requested.

Example
while (eb_step(browser)) {
    update_hud();
    render_overlay();
}
void eb_stop(eb_handle_t browser)

Signal the browser to exit the event loop. eb_run() or eb_step() will return on the next iteration.

void eb_destroy(eb_handle_t browser)

Destroy a browser instance and free all resources (DOM, stylesheets, network connections, cache, rendering surfaces).

Navigation Control

int eb_go_back(eb_handle_t browser)

Navigate to the previous page in history. Returns -1 if no history.

int eb_go_forward(eb_handle_t browser)

Navigate to the next page in history. Returns -1 if at the end.

int eb_reload(eb_handle_t browser)

Reload the current page. Re-fetches resources from network (respects cache headers).

const char * eb_get_url(eb_handle_t browser)

Get the current page URL.

Returns

Current URL string (valid until next navigation).

const char * eb_get_title(eb_handle_t browser)

Get the current page title.

eb_load_state_t eb_get_load_state(eb_handle_t browser)

Get the current page loading state.

Returns

EB_LOAD_IDLE, EB_LOAD_CONNECTING, EB_LOAD_LOADING, EB_LOAD_RENDERING, or EB_LOAD_COMPLETE.

Callbacks

void eb_set_load_callback(eb_handle_t browser, eb_load_callback_t cb, void *ctx)

Register a callback for page load events: void (*)(eb_handle_t, eb_load_state_t state, const char *url, void *ctx)

Example
void on_load(eb_handle_t b, eb_load_state_t state, const char *url, void *ctx) {
    if (state == EB_LOAD_COMPLETE)
        printf("Page loaded: %s\n", url);
}
eb_set_load_callback(browser, on_load, NULL);
void eb_set_navigate_callback(eb_handle_t browser, eb_navigate_callback_t cb, void *ctx)

Register a callback invoked before navigation. Return false from the callback to block navigation (URL filtering for kiosk mode). Signature: bool (*)(eb_handle_t, const char *url, void *ctx)

📄 HTML Parser

Tokenizer and DOM tree construction with error recovery. Header: <ebowser/dom.h>

DOM Node Types

eb_dom_node_t

typeeb_node_type_tELEMENT, TEXT, COMMENT, DOCUMENT, DOCTYPE
tagconst char *Tag name (e.g., "div", "p") — ELEMENT nodes only
textconst char *Text content — TEXT and COMMENT nodes
idconst char *Element id attribute (or NULL)
class_nameconst char *Element class attribute (or NULL)
parenteb_dom_node_t *Parent node
first_childeb_dom_node_t *First child node
next_siblingeb_dom_node_t *Next sibling node
attr_countuint16_tNumber of attributes
attrseb_attr_t *Array of name/value attribute pairs

DOM Query API

eb_dom_node_t * eb_dom_get_document(eb_handle_t browser)

Get the root document node of the current page’s DOM tree.

Returns

Root document node, or NULL if no page loaded.

eb_dom_node_t * eb_dom_get_element_by_id(eb_handle_t browser, const char *id)

Find the first element with the given id attribute.

Parameters
browsereb_handle_tBrowser handle.
idconst char *Element id to search for.
Returns

Matching element node, or NULL.

Example
eb_dom_node_t *header = eb_dom_get_element_by_id(browser, "main-header");
if (header) printf("Found: <%s id='%s'>\n", header->tag, header->id);
eb_dom_node_t ** eb_dom_query_selector_all(eb_handle_t browser, const char *selector, uint32_t *count)

Find all elements matching a CSS selector. Supports tag, class, id, attribute, and descendant selectors.

Parameters
selectorconst char *CSS selector string.
countuint32_t *Output: number of matches.
Returns

Array of matching nodes (caller frees with eb_free()).

Example
uint32_t count;
eb_dom_node_t **links = eb_dom_query_selector_all(browser, "a.nav-link", &count);
for (uint32_t i = 0; i < count; i++) {
    const char *href = eb_dom_get_attr(links[i], "href");
    printf("Link: %s\n", href ? href : "(none)");
}
eb_free(links);
eb_dom_node_t * eb_dom_query_selector(eb_handle_t browser, const char *selector)

Find the first element matching a CSS selector.

DOM Attribute & Content Access

const char * eb_dom_get_attr(eb_dom_node_t *node, const char *name)

Get the value of a named attribute. Returns NULL if not present.

const char * eb_dom_get_text_content(eb_dom_node_t *node)

Get concatenated text content of a node and all descendants. Caller frees with eb_free().

const char * eb_dom_get_inner_html(eb_dom_node_t *node)

Get serialized HTML of an element’s children. Caller frees with eb_free().

Event Handling

int eb_dom_add_event_listener(eb_dom_node_t *node, const char *event, eb_dom_event_cb_t cb, void *ctx)

Attach an event listener to a DOM node.

Parameters
nodeeb_dom_node_t *Target element.
eventconst char *Event name: "click", "input", "submit", "load", "scroll".
cbeb_dom_event_cb_tvoid (*)(eb_dom_node_t *target, const eb_dom_event_t *evt, void *ctx)
ctxvoid *User context.
Returns

0 on success.

Example
void on_click(eb_dom_node_t *target, const eb_dom_event_t *evt, void *ctx) {
    printf("Clicked: <%s>\n", target->tag);
}
eb_dom_node_t *btn = eb_dom_get_element_by_id(browser, "submit-btn");
eb_dom_add_event_listener(btn, "click", on_click, NULL);

🎨 CSS Engine

Stylesheet parsing, cascade, specificity, and computed styles. Header: <ebowser/css.h>

eb_stylesheet_t * eb_css_parse(const char *css_text, size_t len)

Parse a CSS string into an internal stylesheet. Supports selectors, properties, media queries, and @-rules.

Returns

Parsed stylesheet, or NULL on failure.

Example
const char *css = "body { background: #fff; color: #333; font-size: 16px; }";
eb_stylesheet_t *sheet = eb_css_parse(css, strlen(css));
int eb_css_apply(eb_handle_t browser, eb_stylesheet_t *stylesheet)

Apply a stylesheet to the current document. Triggers cascade recalculation and relayout.

Returns

0 on success.

eb_computed_style_t eb_css_computed_style(eb_dom_node_t *node)

Get the fully resolved computed style for a DOM element after cascade, specificity, and inheritance.

Example
eb_dom_node_t *el = eb_dom_get_element_by_id(browser, "content");
eb_computed_style_t style = eb_css_computed_style(el);
printf("Font size: %dpx, Color: #%06X\n", style.font_size, style.color);
void eb_css_free(eb_stylesheet_t *stylesheet)

Free a parsed stylesheet and all associated memory.

Computed Style Structure

eb_computed_style_t

displayeb_display_tBLOCK, INLINE, FLEX, NONE, INLINE_BLOCK
coloruint32_tText color (0xRRGGBB)
background_coloruint32_tBackground color (0xRRGGBB)
font_sizeuint16_tFont size in pixels
font_weightuint16_tFont weight (100-900)
margineb_box_tMargin (top, right, bottom, left) in px
paddingeb_box_tPadding (top, right, bottom, left) in px
border_widtheb_box_tBorder widths in px
positioneb_position_tSTATIC, RELATIVE, ABSOLUTE, FIXED
Supported CSS Properties

Box Model: margin, padding, border, width, height, max-width, max-height, min-width, min-height, box-sizing
Typography: font-size, font-weight, font-family, line-height, text-align, text-decoration, color
Layout: display (block, inline, flex, none), position, top, right, bottom, left, float, clear
Flexbox: flex-direction, justify-content, align-items, flex-wrap, flex-grow, flex-shrink, gap
Visual: background-color, background-image, border-radius, opacity, overflow, visibility

eBowser - Embedded Web Browser - EmbeddedOS

eBowser — Embedded Web Browser v0.1.0

eBowser is a lightweight, embeddable web browser engine for EmbeddedOS. Built from scratch in C/C++ with minimal dependencies, it provides HTML5 parsing, CSS styling, box-model layout, software rendering, and HTTP/HTTPS networking — all in a footprint suitable for resource-constrained embedded devices, kiosks, and IoT dashboards.

Headers: #include <ebowser/*.h> | License: MIT | Backends: SDL2, EoS native, WASM

Architecture Overview

Core Engine: Browser lifecycle, configuration, and embedding API.
HTML Parser: Tokenizer → DOM tree construction with error recovery.
CSS Engine: Stylesheet parsing, cascade, specificity, computed styles.
Layout Engine: Box model, block/inline flow, flexbox, text wrapping.
Rendering: Software rasterizer with SDL2 and EoS display backends.
Network: HTTP/1.1, HTTPS (TLS 1.2/1.3), cookies, connection pooling.
Input: Keyboard, mouse, and touch input abstraction with focus management.
Platform: Portable abstraction layer for SDL2, EoS native, and WebAssembly.

Quick Start
#include <ebowser/ebowser.h>

int main(void) {
    eb_config_t cfg = {
        .width = 1024, .height = 768,
        .title = "eBowser",
        .flags = EB_FLAG_RESIZABLE
    };
    eb_handle_t browser = eb_create(&cfg);
    eb_navigate(browser, "https://example.com");
    eb_run(browser);  // blocks until window closed
    eb_destroy(browser);
    return 0;
}

⚙ Core Engine

Browser lifecycle, configuration, and embedding API. Header: <ebowser/ebowser.h>

Configuration

eb_config_t

widthuint32_tInitial window width in pixels (default: 1024)
heightuint32_tInitial window height in pixels (default: 768)
titleconst char *Window title string
flagsuint32_tBitwise OR of EB_FLAG_* constants
user_agentconst char *Custom User-Agent string (NULL = default)
cache_size_mbuint32_tMax cache size in MB (default: 64)
home_urlconst char *Homepage URL (NULL = about:blank)
proxyconst char *HTTP proxy URL (NULL = direct)
Configuration Flags
EB_FLAG_RESIZABLE=0x01EB_FLAG_FULLSCREEN=0x02EB_FLAG_BORDERLESS=0x04EB_FLAG_NO_JS=0x08EB_FLAG_KIOSK=0x10EB_FLAG_HEADLESS=0x20EB_FLAG_HARDWARE_ACCEL=0x40

Lifecycle

eb_handle_t eb_create(const eb_config_t *config)

Create a new browser instance with the given configuration. Initializes the platform backend, rendering surface, and network stack.

Parameters
configconst eb_config_t *Browser configuration. Pass NULL for defaults (1024×768, resizable).
Returns

eb_handle_t browser handle, or EB_INVALID_HANDLE on failure.

Example
eb_config_t cfg = {
    .width = 800, .height = 600,
    .title = "My Embedded Browser",
    .flags = EB_FLAG_RESIZABLE | EB_FLAG_HARDWARE_ACCEL,
    .cache_size_mb = 32,
    .home_url = "https://example.com"
};
eb_handle_t browser = eb_create(&cfg);
if (browser == EB_INVALID_HANDLE) {
    fprintf(stderr, "Failed to create browser\n");
    return 1;
}
int eb_navigate(eb_handle_t browser, const char *url)

Navigate to a URL. Initiates DNS resolution, HTTP request, HTML parsing, layout, and rendering pipeline. Non-blocking — the page loads asynchronously.

Parameters
browsereb_handle_tBrowser handle.
urlconst char *URL to navigate to (http://, https://, file://, or about:).
Returns

0 on success, negative error code on failure.

Example
eb_navigate(browser, "https://example.com");
eb_navigate(browser, "file:///data/local.html");
eb_navigate(browser, "about:blank");
int eb_run(eb_handle_t browser)

Enter the main event loop. Processes input events, network I/O, layout updates, and rendering. Blocks until the browser window is closed or eb_stop() is called.

Parameters
browsereb_handle_tBrowser handle.
Returns

0 on clean exit.

int eb_step(eb_handle_t browser)

Process a single frame of the event loop. Use instead of eb_run() when embedding the browser in a custom event loop.

Parameters
browsereb_handle_tBrowser handle.
Returns

1 if the browser is still running, 0 if exit was requested.

Example
while (eb_step(browser)) {
    // Custom per-frame logic
    update_hud();
    render_overlay();
}
void eb_stop(eb_handle_t browser)

Signal the browser to exit the event loop. eb_run() or eb_step() will return on the next iteration.

Parameters
browsereb_handle_tBrowser handle.
void eb_destroy(eb_handle_t browser)

Destroy a browser instance and free all associated resources (DOM, stylesheets, network connections, cache, rendering surfaces).

Parameters
browsereb_handle_tBrowser handle to destroy.

Navigation Control

int eb_go_back(eb_handle_t browser)

Navigate to the previous page in history. Returns -1 if no history.

int eb_go_forward(eb_handle_t browser)

Navigate to the next page in history. Returns -1 if at the end.

int eb_reload(eb_handle_t browser)

Reload the current page. Re-fetches resources from network (respects cache headers).

const char * eb_get_url(eb_handle_t browser)

Get the current page URL. Returns pointer to internal string (valid until next navigation).

Returns

Current URL string.

const char * eb_get_title(eb_handle_t browser)

Get the current page <title> content.

Returns

Page title string.

eb_load_state_t eb_get_load_state(eb_handle_t browser)

Get the current page loading state.

Returns

EB_LOAD_IDLE, EB_LOAD_CONNECTING, EB_LOAD_LOADING, EB_LOAD_RENDERING, or EB_LOAD_COMPLETE.

Callbacks

void eb_set_load_callback(eb_handle_t browser, eb_load_callback_t cb, void *ctx)

Register a callback for page load events.

Parameters
browsereb_handle_tBrowser handle.
cbeb_load_callback_tvoid (*)(eb_handle_t, eb_load_state_t state, const char *url, void *ctx)
ctxvoid *User context.
Example
void on_load(eb_handle_t b, eb_load_state_t state, const char *url, void *ctx) {
    if (state == EB_LOAD_COMPLETE)
        printf("Page loaded: %s\n", url);
}
eb_set_load_callback(browser, on_load, NULL);
void eb_set_navigate_callback(eb_handle_t browser, eb_navigate_callback_t cb, void *ctx)

Register a callback invoked before navigation. Return false from the callback to block navigation (e.g., for URL filtering in kiosk mode).

Parameters
cbeb_navigate_callback_tbool (*)(eb_handle_t, const char *url, void *ctx)

📄 HTML Parser

Tokenizer and DOM tree construction with error recovery. Header: <ebowser/dom.h>

DOM Node Types

eb_dom_node_t

typeeb_node_type_tELEMENT, TEXT, COMMENT, DOCUMENT, DOCTYPE
tagconst char *Tag name (e.g., "div", "p") — ELEMENT nodes only
textconst char *Text content — TEXT and COMMENT nodes
idconst char *Element id attribute (or NULL)
class_nameconst char *Element class attribute (or NULL)
parenteb_dom_node_t *Parent node
first_childeb_dom_node_t *First child node
next_siblingeb_dom_node_t *Next sibling node
attr_countuint16_tNumber of attributes
attrseb_attr_t *Array of name/value attribute pairs

DOM Query API

eb_dom_node_t * eb_dom_get_document(eb_handle_t browser)

Get the root document node of the current page’s DOM tree.

Returns

Root document node, or NULL if no page is loaded.

eb_dom_node_t * eb_dom_get_element_by_id(eb_handle_t browser, const char *id)

Find the first element with the given id attribute.

Parameters
browsereb_handle_tBrowser handle.
idconst char *Element id to search for.
Returns

Matching element node, or NULL if not found.

Example
eb_dom_node_t *header = eb_dom_get_element_by_id(browser, "main-header");
if (header) {
    printf("Found header: <%s id='%s'>\n", header->tag, header->id);
}
eb_dom_node_t ** eb_dom_query_selector_all(eb_handle_t browser, const char *selector, uint32_t *count)

Find all elements matching a CSS selector. Supports tag, class, id, attribute, and descendant selectors.

Parameters
browsereb_handle_tBrowser handle.
selectorconst char *CSS selector string.
countuint32_t *Output: number of matches.
Returns

Array of matching nodes (caller must free with eb_free()). NULL if none found.

Example
uint32_t count;
eb_dom_node_t **links = eb_dom_query_selector_all(browser, "a.nav-link", &count);
for (uint32_t i = 0; i < count; i++) {
    const char *href = eb_dom_get_attr(links[i], "href");
    printf("Link: %s\n", href ? href : "(none)");
}
eb_free(links);
eb_dom_node_t * eb_dom_query_selector(eb_handle_t browser, const char *selector)

Find the first element matching a CSS selector.

Returns

First matching node, or NULL.

DOM Attribute Access

const char * eb_dom_get_attr(eb_dom_node_t *node, const char *name)

Get the value of a named attribute on a DOM element.

Parameters
nodeeb_dom_node_t *Element node.
nameconst char *Attribute name (e.g., "href", "src", "class").
Returns

Attribute value string, or NULL if not present.

const char * eb_dom_get_text_content(eb_dom_node_t *node)

Get the concatenated text content of a node and all its descendants.

Returns

Text content string (caller must free with eb_free()).

const char * eb_dom_get_inner_html(eb_dom_node_t *node)

Get the serialized HTML content of an element’s children.

Returns

HTML string (caller must free with eb_free()).

Event Handling

int eb_dom_add_event_listener(eb_dom_node_t *node, const char *event, eb_dom_event_cb_t cb, void *ctx)

Attach an event listener to a DOM node.

Parameters
nodeeb_dom_node_t *Target element.
eventconst char *Event name: "click", "input", "submit", "load", "scroll".
cbeb_dom_event_cb_tvoid (*)(eb_dom_node_t *target, const eb_dom_event_t *evt, void *ctx)
ctxvoid *User context.
Returns

0 on success, negative error code.

Example
void on_click(eb_dom_node_t *target, const eb_dom_event_t *evt, void *ctx) {
    printf("Clicked element: <%s>\n", target->tag);
}
eb_dom_node_t *btn = eb_dom_get_element_by_id(browser, "submit-btn");
eb_dom_add_event_listener(btn, "click", on_click, NULL);

🎨 CSS Engine

Stylesheet parsing, cascade, specificity, and computed styles. Header: <ebowser/css.h>

eb_stylesheet_t * eb_css_parse(const char *css_text, size_t len)

Parse a CSS string into an internal stylesheet representation. Supports selectors, properties, media queries, and @-rules.

Parameters
css_textconst char *CSS source text.
lensize_tLength of CSS text in bytes.
Returns

Parsed stylesheet, or NULL on parse failure.

Example
const char *css = "body { background: #fff; color: #333; font-size: 16px; }";
eb_stylesheet_t *sheet = eb_css_parse(css, strlen(css));
int eb_css_apply(eb_handle_t browser, eb_stylesheet_t *stylesheet)

Apply a stylesheet to the current document. Triggers cascade recalculation and relayout.

Parameters
browsereb_handle_tBrowser handle.
stylesheeteb_stylesheet_t *Parsed stylesheet.
Returns

0 on success.

eb_computed_style_t eb_css_computed_style(eb_dom_node_t *node)

Get the fully resolved computed style for a DOM element after cascade, specificity, and inheritance.

Parameters
nodeeb_dom_node_t *Target element node.
Returns

eb_computed_style_t struct with all resolved CSS properties.

Example
eb_dom_node_t *el = eb_dom_get_element_by_id(browser, "content");
eb_computed_style_t style = eb_css_computed_style(el);
printf("Font size: %dpx\n", style.font_size);
printf("Color: #%06X\n", style.color);
printf("Display: %s\n", eb_display_str(style.display));
void eb_css_free(eb_stylesheet_t *stylesheet)

Free a parsed stylesheet and all associated memory.

Computed Style Structure

eb_computed_style_t

displayeb_display_tBLOCK, INLINE, FLEX, NONE, INLINE_BLOCK
coloruint32_tText color (0xRRGGBB)
background_coloruint32_tBackground color (0xRRGGBB)
font_sizeuint16_tFont size in pixels
font_weightuint16_tFont weight (100-900)
margineb_box_tMargin (top, right, bottom, left) in px
paddingeb_box_tPadding (top, right, bottom, left) in px
border_widtheb_box_tBorder widths in px
border_coloruint32_tBorder color (0xRRGGBB)
width / heighteb_css_value_tDimensions (px, %, auto)
positioneb_position_tSTATIC, RELATIVE, ABSOLUTE, FIXED
overfloweb_overflow_tVISIBLE, HIDDEN, SCROLL, AUTO
Supported CSS Properties

Box Model: margin, padding, border, width, height, max-width, max-height, min-width, min-height, box-sizing
Typography: font-size, font-weight, font-family, line-height, text-align, text-decoration, color
Layout: display (block, inline, flex, none), position, top, right, bottom, left, float, clear
Flexbox: flex-direction, justify-content, align-items, flex-wrap, flex-grow, flex-shrink, gap
Visual: background-color, background-image, border-radius, opacity, overflow, visibility
Other: cursor, z-index, list-style, @media queries

📐 Layout Engine

Box model computation, block/inline flow, flexbox, and text wrapping. Header: <ebowser/layout.h>

int eb_layout_compute(eb_handle_t browser)

Compute the layout for the entire document. Traverses the DOM tree, applies CSS box model, resolves widths/heights, positions elements, wraps text, and produces a layout tree with absolute coordinates.

Parameters
browsereb_handle_tBrowser handle.
Returns

0 on success, negative error code.

eb_rect_t eb_layout_get_rect(eb_dom_node_t *node)

Get the computed bounding rectangle (position and size) of a DOM element after layout.

Parameters
nodeeb_dom_node_t *Element node with completed layout.
Returns

eb_rect_t with x, y, width, height in pixels (relative to document).

Example
eb_dom_node_t *el = eb_dom_get_element_by_id(browser, "content");
eb_rect_t rect = eb_layout_get_rect(el);
printf("Position: (%d, %d), Size: %dx%d\n", rect.x, rect.y, rect.width, rect.height);
eb_box_metrics_t eb_layout_get_box_metrics(eb_dom_node_t *node)

Get the full box model metrics (content, padding, border, margin) for an element.

Returns

eb_box_metrics_t with content_rect, padding_rect, border_rect, margin_rect.

eb_dom_node_t * eb_layout_hit_test(eb_handle_t browser, int32_t x, int32_t y)

Find the topmost DOM element at the given document coordinates (used for click/hover handling).

Parameters
browsereb_handle_tBrowser handle.
xint32_tX coordinate in document space.
yint32_tY coordinate in document space.
Returns

Topmost element at the point, or NULL.

eb_size_t eb_layout_get_document_size(eb_handle_t browser)

Get the total size of the laid-out document (for scroll bounds calculation).

Returns

eb_size_t with width and height of the full document.

void eb_layout_scroll_to(eb_handle_t browser, int32_t x, int32_t y)

Scroll the viewport to the specified document coordinates.

eb_point_t eb_layout_get_scroll_pos(eb_handle_t browser)

Get the current scroll position of the viewport.

Returns

eb_point_t with x, y scroll offset.

eb_rect_t

xint32_tX position (px, document-relative)
yint32_tY position (px, document-relative)
widthint32_tWidth in pixels
heightint32_tHeight in pixels

🎨 Rendering

Software rasterizer with SDL2 and EoS display backends. Header: <ebowser/render.h>

int eb_render_frame(eb_handle_t browser)

Render the current page to the display surface. Rasterizes backgrounds, borders, text, images, and scrollbars.

Returns

0 on success.

int eb_render_text(eb_handle_t browser, const char *text, int32_t x, int32_t y, uint32_t color, uint16_t size)

Render text at screen coordinates. Used for HUD overlays.

Parameters
textconst char *UTF-8 text string.
x, yint32_tScreen coordinates.
coloruint32_tText color (0xRRGGBB).
sizeuint16_tFont size in pixels.
int eb_render_image(eb_handle_t browser, const eb_image_t *img, const eb_rect_t *dest)

Render a decoded image to the display at the specified destination rectangle.

int eb_render_rect(eb_handle_t browser, const eb_rect_t *rect, uint32_t color, bool filled)

Render a filled or outline rectangle on the display surface.

int eb_render_to_bitmap(eb_handle_t browser, uint8_t *pixels, uint32_t w, uint32_t h, uint32_t stride)

Render the page to an off-screen RGBA bitmap buffer (headless screenshot).

Parameters
pixelsuint8_t *Output buffer (RGBA, caller-allocated).
w, huint32_tBitmap dimensions.
strideuint32_tRow stride in bytes.
Example
uint8_t *buf = malloc(1024 * 768 * 4);
eb_render_to_bitmap(browser, buf, 1024, 768, 1024 * 4);
save_png("shot.png", buf, 1024, 768);
free(buf);
Rendering Pipeline

1. Backgrounds → borders → block content → inline/text → positioned elements → scrollbars.
2. Built-in bitmap font with UTF-8 and glyph caching. PNG/JPEG via stb_image.
3. Backends: SDL2 (desktop), EoS framebuffer (embedded), WASM Canvas (web).

🌐 Network Stack

HTTP/HTTPS client, DNS, cookies, connection pooling. Header: <ebowser/net.h>

eb_net_request_t * eb_net_request(const eb_net_config_t *config)

Create and send an HTTP/HTTPS request. Supports GET, POST, PUT, DELETE. Asynchronous with callback.

Parameters
configconst eb_net_config_t *Request config: url, method, headers, body, timeout_ms, callback, ctx.
Returns

Request handle, or NULL on failure.

Example
void on_resp(eb_net_request_t *req, void *ctx) {
    printf("Status: %d, Body: %.*s\n",
        req->status_code, (int)req->body_len, req->body);
}
eb_net_config_t cfg = {
    .url = "https://api.example.com/data",
    .method = EB_NET_GET,
    .timeout_ms = 10000,
    .callback = on_resp
};
eb_net_request(&cfg);
int eb_net_set_proxy(eb_handle_t browser, const char *proxy_url)

Configure HTTP proxy. Pass NULL to disable.

int eb_net_set_cookie(eb_handle_t browser, const char *domain, const char *name, const char *value, uint32_t max_age)

Set a cookie. max_age=0 for session cookie.

const char * eb_net_get_cookie(eb_handle_t browser, const char *domain, const char *name)

Retrieve a cookie value. Returns NULL if not found.

int eb_net_clear_cookies(eb_handle_t browser) / eb_net_clear_cache(eb_handle_t browser)

Clear all cookies or the HTTP response cache.

eb_net_config_t

urlconst char *Request URL
methodeb_net_method_tEB_NET_GET, POST, PUT, DELETE, HEAD
headersconst eb_header_t *Array of name/value header pairs
header_countuint32_tNumber of custom headers
bodyconst uint8_t *Request body (POST/PUT)
body_lensize_tBody length in bytes
timeout_msuint32_tTimeout (default: 30000)
callbackeb_net_callback_tCompletion callback

⌨ Input Layer

Keyboard, mouse, and touch input abstraction. Header: <ebowser/input.h>

int eb_input_inject_key(eb_handle_t browser, eb_keycode_t key, eb_key_action_t action, uint32_t modifiers)

Inject a keyboard event. Used for programmatic input and on-screen keyboards.

Parameters
keyeb_keycode_tKey code (EB_KEY_A..Z, 0..9, ENTER, TAB, ESCAPE, etc.).
actioneb_key_action_tEB_KEY_DOWN, EB_KEY_UP, or EB_KEY_PRESS.
modifiersuint32_tBitwise OR: EB_MOD_SHIFT, EB_MOD_CTRL, EB_MOD_ALT.
Example
// Ctrl+A (select all)
eb_input_inject_key(browser, EB_KEY_A, EB_KEY_PRESS, EB_MOD_CTRL);
// Press Enter
eb_input_inject_key(browser, EB_KEY_ENTER, EB_KEY_PRESS, 0);
int eb_input_inject_mouse(eb_handle_t browser, eb_mouse_event_t type, int32_t x, int32_t y, eb_mouse_button_t button)

Inject a mouse event.

Parameters
typeeb_mouse_event_tEB_MOUSE_MOVE, DOWN, UP, SCROLL.
x, yint32_tScreen coordinates.
buttoneb_mouse_button_tEB_MOUSE_LEFT, RIGHT, MIDDLE.
Example
eb_input_inject_mouse(browser, EB_MOUSE_DOWN, 200, 300, EB_MOUSE_LEFT);
eb_input_inject_mouse(browser, EB_MOUSE_UP, 200, 300, EB_MOUSE_LEFT);
int eb_input_inject_touch(eb_handle_t browser, eb_touch_event_t type, uint32_t touch_id, int32_t x, int32_t y)

Inject a touch event for touchscreen devices.

Parameters
typeeb_touch_event_tEB_TOUCH_START, MOVE, END, CANCEL.
touch_iduint32_tUnique touch point ID (multitouch).
x, yint32_tScreen coordinates.
int eb_input_set_focus(eb_handle_t browser, eb_dom_node_t *node)

Set keyboard focus to a DOM element (input, textarea).

eb_dom_node_t * eb_input_get_focus(eb_handle_t browser)

Get the currently focused element. Returns NULL if none.

💻 Platform Abstraction

SDL2, EoS native, and WASM backends. Header: <ebowser/platform.h>

int eb_platform_init(eb_platform_t platform)

Initialize the platform backend. Auto-detected if not called.

Parameters
platformeb_platform_tEB_PLATFORM_SDL2, EB_PLATFORM_EOS, EB_PLATFORM_WASM, or EB_PLATFORM_AUTO.
int eb_platform_get_display_info(eb_display_info_t *info)

Get display info: resolution, DPI, refresh rate, color depth.

Example
eb_display_info_t info;
eb_platform_get_display_info(&info);
printf("Display: %dx%d @ %d Hz, %d DPI\n",
    info.width, info.height, info.refresh_hz, info.dpi);
void eb_platform_deinit(void)

Deinitialize the platform backend and release display resources.

uint64_t eb_platform_get_time_ms(void)

Get monotonic time in milliseconds for animations and timing.

int eb_platform_set_clipboard(const char *text) / eb_platform_get_clipboard(char *buf, size_t len)

Set/get system clipboard text content.

eb_display_info_t

widthuint32_tDisplay width in pixels
heightuint32_tDisplay height in pixels
dpiuint32_tDots per inch
refresh_hzuint32_tRefresh rate in Hz
color_depthuint8_tBits per pixel (16, 24, or 32)
platformeb_platform_tActive platform backend

🔒 Security

Content security policies, TLS, and sandboxing. Header: <ebowser/security.h>

int eb_security_set_policy(eb_handle_t browser, eb_security_policy_t policy)

Set the content security policy level.

Parameters
policyeb_security_policy_tEB_POLICY_PERMISSIVE, EB_POLICY_STANDARD (same-origin), or EB_POLICY_STRICT (whitelist).
int eb_security_add_allowed_origin(eb_handle_t browser, const char *origin)

Add an origin to the whitelist (for EB_POLICY_STRICT). Non-whitelisted origins are blocked.

Example
eb_security_set_policy(browser, EB_POLICY_STRICT);
eb_security_add_allowed_origin(browser, "https://example.com");
eb_security_add_allowed_origin(browser, "https://cdn.example.com");
int eb_tls_set_ca_bundle(eb_handle_t browser, const char *path)

Set the CA certificate bundle for TLS verification. NULL for system default.

int eb_tls_set_verify(eb_handle_t browser, bool verify)

Enable/disable TLS certificate verification. Disable only for development.

int eb_security_set_url_filter(eb_handle_t browser, eb_url_filter_t cb, void *ctx)

Set a URL filter callback: bool (*)(const char *url, void *ctx) — return true to allow, false to block.

Example
bool kiosk_filter(const char *url, void *ctx) {
    return strstr(url, "example.com") != NULL;
}
eb_security_set_url_filter(browser, kiosk_filter, NULL);

Security Features

Same-Origin PolicyCross-origin resource access restricted by default
TLS 1.2/1.3Encrypted connections with certificate verification
URL FilteringWhitelist/blacklist for kiosk and parental controls
CSP HeadersContent-Security-Policy HTTP header enforcement
Cookie SecurityHttpOnly, Secure, SameSite attribute support
Mixed ContentHTTP resources blocked on HTTPS pages

💻 CLI Reference

Command-line options for the eBowser standalone executable.

Usage
ebowser [OPTIONS] [URL]

ebowser https://example.com
ebowser --resolution 800x480 --fullscreen https://dashboard.local
ebowser --no-js --kiosk https://signage.example.com
ebowser --headless --screenshot out.png https://example.com

Command-Line Options

--resolution WxHstringWindow resolution (e.g., 1024x768)
--fullscreenflagLaunch in fullscreen mode
--no-jsflagDisable JavaScript execution
--kioskflagKiosk mode: fullscreen, no UI chrome
--headlessflagRun without display (server-side rendering)
--cache-size NintegerHTTP cache size in MB (default: 64)
--log-level LEVELstringerror, warn, info, debug, trace
--proxy URLstringHTTP proxy URL
--user-agent STRstringCustom User-Agent string
--screenshot FILEstringSave screenshot to FILE (headless)
--ca-bundle FILEstringCustom CA certificate bundle (PEM)
--no-tls-verifyflagDisable TLS verification (dev only)
--allowed-originsstringComma-separated allowed origins
--home URLstringHomepage URL
--versionflagPrint version and exit
Embedded Kiosk Example
eb_config_t cfg = {
    .width = 800, .height = 480,
    .title = "Dashboard",
    .flags = EB_FLAG_FULLSCREEN | EB_FLAG_KIOSK | EB_FLAG_NO_JS
};
eb_handle_t b = eb_create(&cfg);
eb_security_set_policy(b, EB_POLICY_STRICT);
eb_security_add_allowed_origin(b, "https://dashboard.local");
eb_navigate(b, "https://dashboard.local");
eb_run(b);
eb_destroy(b);