JavaScriptBridge
Web bridge for JavaScript, callbacks and byte buffers.
Web-build bridge to page JavaScript. Desktop SDK-class/singleton availability does not establish support: object/eval methods are stubbed outside Web or without javascript_eval. Current C# exporter 1.0.0 does not implement Web; this reference promises no C# browser export.
GetInterface looks up exact window[name]; CreateObject invokes its constructor. Expose a limited adapter API and check script readiness. GetInterface/CreateCallback return owned RefCounted wrappers; do not release the engine-owned Singleton. Callbacks accept one engine Array containing all JS arguments; retain the wrapper and stop external delivery before releasing it. Native Callable return is currently not forwarded as a synchronous JS result.
Eval and object-bridge conversions differ. DataView/non-Uint8Array copying currently includes the entire backing buffer; use the executed copyViewBytes from the guide. The defect was reproduced in actual bridge JS with mock native memory and was not fixed in the engine. Native bool Variant fidelity and C#/WASM ABI were not tested.
DownloadBuffer requests a browser download, ForceFsSync schedules synchronization and PwaUpdate requests service-worker work. None is a general save/update completion receipt. Twenty-one JS checks ran; real browser permissions, DOM/download, storage, PWA and managed export are not accepted as verified.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Properties1
SingletonProperty
public static JavaScriptBridgeInstance Singleton { get; }Engine-owned JavaScriptBridge object. Do not create another instance or Free/Dispose it. Desktop singleton availability does not establish browser support: methods may be stubs. Distinct from your own RefCounted wrappers returned by GetInterface/CreateCallback.
Methods12
CreateCallbackJavaScriptObject
public static JavaScriptObject CreateCallback(Callable callable);Creates a RefCounted JavaScriptObject function from a Callable accepting one engine Array containing all JS arguments. Retain its wrapper through subscription/waiting and stop external delivery before releasing it. Not GetInterface. Current native code does not forward the Callable return value to JS; threaded proxy may defer delivery. Null outside Web/without javascript_eval.
| Name | Type | Default |
|---|---|---|
callable | Callable | — |
callableCallable with one Array parameter containing the JavaScript arguments. Validate count/types; do not rely on a synchronous return value.
JavaScriptObjectOwned RefCounted callback wrapper or null in unsupported builds. Retain through the external subscription; disable delivery before releasing your reference.
CreateObject2 overloads
public static Variant CreateObject(string @object, params Variant[] args);Calls new windowname, returning a Variant containing the new JS-object wrapper. Exact name, not a dotted path; the page constructor must be ready. Constructor absence/failure can produce an empty result with diagnostics. Does not promise arbitrary engine-collection conversion; use supported scalar/wrapper values. Stub outside Web/without javascript_eval.
| Name | Type | Default |
|---|---|---|
object | string | — |
args | Variant[] | — |
objectExact constructor name in window, not an expression or dotted path. Must be loaded before the call.
argsConstructor arguments in order. Use supported scalars and JavaScriptObject wrappers; ordinary engine Array/Dictionary values are not promised as JS collections.
VariantVariant containing the created JS-object wrapper or empty result on failure/stub; not a success code.
public static Variant CreateObject(string @object, ReadOnlySpan<Variant> args);Calls new windowname, returning a Variant containing the new JS-object wrapper. Exact name, not a dotted path; the page constructor must be ready. Constructor absence/failure can produce an empty result with diagnostics. Does not promise arbitrary engine-collection conversion; use supported scalar/wrapper values. Stub outside Web/without javascript_eval.
| Name | Type | Default |
|---|---|---|
object | string | — |
args | ReadOnlySpan<Variant> | — |
objectExact constructor name in window, not an expression or dotted path. Must be loaded before the call.
argsConstructor arguments in order. Use supported scalars and JavaScriptObject wrappers; ordinary engine Array/Dictionary values are not promised as JS collections.
VariantVariant containing the created JS-object wrapper or empty result on failure/stub; not a success code.
DownloadBuffer2 overloads
public static void DownloadBuffer(byte[] buffer, string name, string mime = "application/octet-stream");Requests a browser download of copied bytes through a Blob and temporary link. Returns no disk-save confirmation, exports no project and does not synchronize user://. Does nothing outside Web. Check the actual file and browser policy; MIME labels content without converting bytes.
| Name | Type | Default |
|---|---|---|
buffer | byte[] | — |
name | string | — |
mime | string | "application/octet-stream" |
bufferFile bytes to download; MIME/extension do not change their encoding. Validate content before requesting download.
nameSuggested browser-download filename, not an absolute write path on the user’s computer.
mimeContent MIME type. The byte[] overload defaults to application/octet-stream; the ReadOnlySpan<byte> overload requires it explicitly. Does not convert data.
public static void DownloadBuffer(ReadOnlySpan<byte> buffer, string name, string mime);Requests a browser download of copied bytes through a Blob and temporary link. Returns no disk-save confirmation, exports no project and does not synchronize user://. Does nothing outside Web. Check the actual file and browser policy; MIME labels content without converting bytes.
| Name | Type | Default |
|---|---|---|
buffer | ReadOnlySpan<byte> | — |
name | string | — |
mime | string | — |
bufferFile bytes to download; MIME/extension do not change their encoding. Validate content before requesting download.
nameSuggested browser-download filename, not an absolute write path on the user’s computer.
mimeContent MIME type. The byte[] overload defaults to application/octet-stream; the ReadOnlySpan<byte> overload requires it explicitly. Does not convert data.
EvalVariant
public static Variant Eval(string code, bool useGlobalExecutionContext = false);Executes JS code, using local execution context by default. JS numbers return a floating Variant; strings and byte buffers have dedicated paths, ordinary objects/functions return nil. Exceptions are logged and can also yield nil. DataView/non-Uint8Array views currently copy the whole backing buffer: normalize with copyViewBytes first. A JS bool tag exists but C++ returns a uint32 field into Variant; native bool fidelity is unverified. Nil outside Web/without javascript_eval.
| Name | Type | Default |
|---|---|---|
code | string | — |
useGlobalExecutionContext | bool | false |
codeJavaScript code to execute. Prefer a named adapter API and value arguments; avoid concatenating executable code from external text.
useGlobalExecutionContextFalse by default for local eval context; true selects indirect global eval affecting page namespace. Does not enable arbitrary object-return conversion.
VariantLimited Variant result. Nil is ambiguous: null, unsupported type, error or disabled bridge. Byte-range and native-bool limits are described above.
ForceFsSyncvoid
public static void ForceFsSync();Marks the filesystem for later synchronization when browser persistence is available. Void method: does not await writeback, confirm durability or initiate a download. Does nothing outside Web. A successful virtual-FS write and completed IndexedDB persistence are separate states.
GetInterfaceJavaScriptObject
public static JavaScriptObject GetInterface(string @interface);Gets a new wrapper for exact window[name]. Does not interpret app.sdk as a path; expose an explicit page-global adapter and wait for readiness. A missing Web name gives native error/null; null outside Web or without javascript_eval. The wrapper is a RefCounted handle: releasing your own reference does not delete the global JS object. Do not release the bridge singleton.
| Name | Type | Default |
|---|---|---|
interface | string | — |
interfaceExact window-global name, for example ReckfellPage; no nested-property traversal.
JavaScriptObjectNew RefCounted wrapper for the global JS object, or null; ownership of the page global is not transferred.
IsJsBufferbool
public static bool IsJsBuffer(JavaScriptObject javascriptObject);Checks whether a JavaScriptObject is an ArrayBuffer or ArrayBuffer view. False for null and outside Web/without javascript_eval. True validates neither expected length/format nor view-range preservation: current DataView/nonbyte copy paths may include the entire backing buffer.
| Name | Type | Default |
|---|---|---|
javascriptObject | JavaScriptObject | — |
javascriptObjectWrapper of the JS value to inspect; null gives false. Establishes no buffer length/schema.
boolJS-value shape check, not validation of content or preserved range.
JsBufferToPackedByteArraybyte[]
public static byte[] JsBufferToPackedByteArray(JavaScriptObject javascriptBuffer);Copies a JavaScript buffer into a new byte[]. Checks IsJsBuffer first; invalid input emits a native error and gives an empty array. DataView/non-Uint8Array views currently expand to their whole backing ArrayBuffer without offset/length. Supply a fresh Uint8Array for the intended range, for example the guide’s copyViewBytes result. Copy, not shared memory or JS-buffer ownership transfer.
| Name | Type | Default |
|---|---|---|
javascriptBuffer | JavaScriptObject | — |
javascriptBufferJS-buffer wrapper. For DataView/nonbyte views first create a separate Uint8Array for the intended byte range. Invalid input emits a native error/empty result.
byte[]New managed byte[] copy; empty for a stub/error and also for a legitimate empty buffer. Nonbyte views need the documented workaround.
PwaNeedsUpdatebool
public static bool PwaNeedsUpdate();Reads the cached OS waiting-PWA-update flag; false outside Web. Performs no network/version check and does not establish that registration still has a waiting update. True is set by the service-worker notification path; verify update application separately.
boolCached waiting flag, or false outside Web; not a live service-worker query.
PwaUpdateError
public static Error PwaUpdate();Requests an update from the waiting service worker. On Web the bridge asynchronously gets registration and sends waiting.postMessage("update"). Ok means the synchronous bridge accepted a request, not completed installation/reload; registration may no longer have waiting. Save state first. Unavailable outside Web; the actual PWA workflow was not executed here.
ErrorError.Ok for a bridge-accepted request, Failed for refusal, Unavailable outside Web. Not confirmation of completed asynchronous update.
Signals and events1
PwaUpdateAvailableEvent
public static event Action PwaUpdateAvailable;Parameterless notification that a PWA update is waiting; native code sets the waiting flag first. Not an engine-release notification or proof of installed update. Save state and decide when to call PwaUpdate; avoid unconditionally reloading unfinished gameplay.