Expand description
§Oxide SDK
Guest-side SDK for building WebAssembly applications that run inside the
Oxide browser. This crate provides safe Rust wrappers around the raw
host-imported functions exposed by the "oxide" module.
§Quick Start
ⓘ
use oxide_sdk::*;
#[no_mangle]
pub extern "C" fn start_app() {
log("Hello from Oxide!");
canvas_clear(30, 30, 46, 255);
canvas_text(20.0, 40.0, 28.0, 255, 255, 255, "Welcome to Oxide");
}Modules§
- proto
- Lightweight protobuf wire-format encoder/decoder.
Structs§
- Fetch
Response - Response from an HTTP fetch call.
- Uploaded
File - File returned from the native file picker.
Constants§
- KEY_0
- KEY_1
- KEY_2
- KEY_3
- KEY_4
- KEY_5
- KEY_6
- KEY_7
- KEY_8
- KEY_9
- KEY_A
- KEY_B
- KEY_
BACKSPACE - KEY_C
- KEY_D
- KEY_
DELETE - KEY_
DOWN - KEY_E
- KEY_END
- KEY_
ENTER - KEY_
ESCAPE - KEY_F
- KEY_G
- KEY_H
- KEY_
HOME - KEY_I
- KEY_J
- KEY_K
- KEY_L
- KEY_
LEFT - KEY_M
- KEY_N
- KEY_O
- KEY_P
- KEY_
PAGE_ DOWN - KEY_
PAGE_ UP - KEY_Q
- KEY_R
- KEY_
RIGHT - KEY_S
- KEY_
SPACE - KEY_T
- KEY_TAB
- KEY_U
- KEY_UP
- KEY_V
- KEY_W
- KEY_X
- KEY_Y
- KEY_Z
Functions§
- alt_
held - Returns
trueif Alt is held. - base64_
decode - Decode a base64-encoded string back to bytes.
- base64_
encode - Base64-encode arbitrary bytes.
- canvas_
circle - Draw a filled circle.
- canvas_
clear - Clear the canvas with a solid RGBA color.
- canvas_
dimensions - Returns
(width, height)of the canvas in pixels. - canvas_
image - Draw an image on the canvas from encoded image bytes (PNG, JPEG, GIF, WebP). The browser decodes the image and renders it at the given rectangle.
- canvas_
line - Draw a line between two points.
- canvas_
rect - Draw a filled rectangle.
- canvas_
text - Draw text on the canvas.
- clear_
hyperlinks - Remove all previously registered hyperlinks.
- clipboard_
read - Read text from the system clipboard.
- clipboard_
write - Copy text to the system clipboard.
- ctrl_
held - Returns
trueif Ctrl (or Cmd on macOS) is held. - error
- Print an error to the browser console.
- fetch
- Perform an HTTP request. Returns the status code and response body.
- fetch_
delete - HTTP DELETE.
- fetch_
get - HTTP GET request.
- fetch_
post - HTTP POST with raw bytes.
- fetch_
post_ proto - HTTP POST with protobuf body (sets
Content-Type: application/protobuf). - fetch_
put - HTTP PUT with raw bytes.
- get_
location - Get the device’s mock geolocation as a
"lat,lon"string. - get_
state - Retrieve the opaque state bytes attached to the current history entry.
Returns
Noneif no state has been set. - get_url
- Get the URL of the currently loaded page.
- hash_
sha256 - Compute the SHA-256 hash of the given data. Returns 32 bytes.
- hash_
sha256_ hex - Return SHA-256 hash as a lowercase hex string.
- history_
back - Navigate backward in history. Returns
trueif a navigation was queued. - history_
forward - Navigate forward in history. Returns
trueif a navigation was queued. - history_
length - Return the total number of entries in the history stack.
- key_
down - Returns
trueif the given key is currently held down. SeeKEY_*constants for key codes. - key_
pressed - Returns
trueif the given key was pressed this frame. - kv_
store_ delete - Delete a key from the persistent KV store. Returns
trueon success. - kv_
store_ get - Retrieve a value from the persistent KV store.
Returns
Noneif the key does not exist. - kv_
store_ get_ str - Convenience wrapper: retrieve a UTF-8 string value.
- kv_
store_ set - Store a key-value pair in the persistent on-disk KV store.
Returns
trueon success. - kv_
store_ set_ str - Convenience wrapper: store a UTF-8 string value.
- load_
module - Fetch and execute another
.wasmmodule from a URL. The loaded module shares the same canvas, console, and storage context. Returns 0 on success, negative error code on failure. - log
- Print a message to the browser console (log level).
- modifiers
- Returns modifier key state as a bitmask: bit 0 = Shift, bit 1 = Ctrl, bit 2 = Alt.
- mouse_
button_ clicked - Returns
trueif the given mouse button was clicked this frame. - mouse_
button_ down - Returns
trueif the given mouse button is currently held down. Button 0 = primary (left), 1 = secondary (right), 2 = middle. - mouse_
position - Get the mouse position in canvas-local coordinates.
- navigate
- Navigate to a new URL. The URL can be absolute or relative to the current
page. Navigation happens asynchronously after the current
start_appreturns. Returns 0 on success, negative on invalid URL. - notify
- Send a notification to the user (rendered in the browser console).
- push_
state - Push a new entry onto the browser’s history stack without triggering a
module reload. This is analogous to
history.pushState()in web browsers. - random_
f64 - Get a random f64 in [0, 1).
- random_
u64 - Get a random u64 from the host.
- register_
hyperlink - Register a rectangular region on the canvas as a clickable hyperlink.
- replace_
state - Replace the current history entry (no new entry is pushed).
Analogous to
history.replaceState(). - scroll_
delta - Get the scroll wheel delta for this frame.
- shift_
held - Returns
trueif Shift is held. - storage_
get - Retrieve a value from local storage. Returns empty string if not found.
- storage_
remove - Remove a key from local storage.
- storage_
set - Store a key-value pair in sandboxed local storage.
- time_
now_ ms - Get the current time in milliseconds since the UNIX epoch.
- ui_
button - Render a button at the given position. Returns
trueif it was clicked on the previous frame. - ui_
checkbox - Render a checkbox. Returns the current checked state.
- ui_
slider - Render a slider. Returns the current value.
- ui_
text_ input - Render a single-line text input. Returns the current text content.
- upload_
file - Opens the native OS file picker and returns the selected file.
Returns
Noneif the user cancels. - url_
decode - Decode a percent-encoded string.
- url_
encode - Percent-encode a string for safe inclusion in URL components.
- url_
resolve - Resolve a relative URL against a base URL (WHATWG algorithm).
Returns
Noneif either URL is invalid. - warn
- Print a warning to the browser console.