### Basic Runtime Lifecycle Source: https://hexdocs.pm/quickbeam Demonstrates starting a runtime, evaluating JavaScript code, and stopping the runtime. ```elixir iex> {:ok, rt} = QuickBEAM.start() iex> {:ok, 3} = QuickBEAM.eval(rt, "1 + 2") iex> QuickBEAM.stop(rt) :ok ``` -------------------------------- ### QuickBEAM.start/1 Source: https://hexdocs.pm/quickbeam Starts a new JavaScript runtime instance with configurable options for memory, stack size, and environment APIs. ```APIDOC ## QuickBEAM.start(opts \\ []) ### Description Starts a new JavaScript runtime. Returns `{:ok, pid}` on success. ### Parameters - **opts** (keyword) - Optional - Configuration options including :name, :handlers, :script, :apis, :define, :memory_limit, :max_stack_size, :wasm_stack_size, :wasm_heap_size, :max_convert_depth, and :max_convert_nodes. ``` -------------------------------- ### Start a new JavaScript runtime Source: https://hexdocs.pm/quickbeam Initializes a new JS runtime with configurable options for memory, stack size, and API surfaces. ```elixir @spec start(keyword()) :: GenServer.on_start() ``` ```elixir QuickBEAM.start(script: "build.ts", define: %{"outputDir" => "/tmp/site"}) ``` -------------------------------- ### Get memory usage statistics Source: https://hexdocs.pm/quickbeam Returns a map of current QuickJS memory usage metrics. ```elixir @spec memory_usage(runtime()) :: map() ``` -------------------------------- ### Supervising Runtimes Source: https://hexdocs.pm/quickbeam Configures a QuickBEAM runtime as a child process within an OTP supervision tree. ```elixir children = [ {QuickBEAM, name: :app, script: "priv/js/app.js", handlers: %{...}}, ] Supervisor.start_link(children, strategy: :one_for_one) ``` -------------------------------- ### load_addon(runtime, path, opts) Source: https://hexdocs.pm/quickbeam Loads a native .node addon via N-API and returns its exports. ```APIDOC ## load_addon(runtime, path, opts) ### Description Load a native addon (.node file) via N-API. The addon is loaded with dlopen and its entry point is called. ### Signature `load_addon(runtime(), String.t(), keyword()) :: {:ok, term()} | {:error, term()}` ### Options - **:as** (String.t) - Optional - Set the addon's exports as a global JS variable with this name. ``` -------------------------------- ### memory_usage(runtime) Source: https://hexdocs.pm/quickbeam Returns QuickJS memory usage statistics. ```APIDOC ## memory_usage(runtime) ### Description Return QuickJS memory usage statistics. ### Signature `memory_usage(runtime()) :: map()` ``` -------------------------------- ### info(runtime) Source: https://hexdocs.pm/quickbeam Returns runtime diagnostics including registered handlers, memory stats, and JS global count. ```APIDOC ## info(runtime) ### Description Return runtime diagnostics: registered handlers, memory stats, and JS global count. ### Signature `info(runtime()) :: map()` ``` -------------------------------- ### load_bytecode(runtime, bytecode) Source: https://hexdocs.pm/quickbeam Executes precompiled bytecode within the runtime context. ```APIDOC ## load_bytecode(runtime, bytecode) ### Description Execute precompiled bytecode from compile/2. The bytecode runs in the current runtime's context, with access to all globals, handlers, and builtins. ### Signature `load_bytecode(runtime(), binary()) :: js_result()` ``` -------------------------------- ### Load a native addon Source: https://hexdocs.pm/quickbeam Loads a .node file via N-API and returns its exports. Use the :as option to expose exports as a global JS variable. ```elixir @spec load_addon(runtime(), String.t(), keyword()) :: {:ok, term()} | {:error, term()} ``` ```elixir QuickBEAM.load_addon(rt, "/path/to/addon.node") QuickBEAM.load_addon(rt, "/path/to/crc32.node", as: "crc32") QuickBEAM.eval(rt, "crc32.crc32('hello')") ``` -------------------------------- ### load_module(runtime, name, code) Source: https://hexdocs.pm/quickbeam Loads an ES module into the runtime. ```APIDOC ## load_module(runtime, name, code) ### Description Load an ES module into the runtime. ### Signature `load_module(runtime(), String.t(), String.t()) :: :ok | {:error, String.t()}` ``` -------------------------------- ### Execute precompiled bytecode Source: https://hexdocs.pm/quickbeam Runs bytecode generated by compile/2 within the current runtime context. ```elixir @spec load_bytecode(runtime(), binary()) :: js_result() ``` -------------------------------- ### call(runtime, fn_name, args, opts) Source: https://hexdocs.pm/quickbeam Calls a global JavaScript function by name within the specified runtime. Arguments are converted to JS values, and the result is returned to Elixir. ```APIDOC ## call(runtime, fn_name, args, opts) ### Description Call a global JavaScript function by name. Arguments are converted to JS values; the return value is converted back. Promise-returning functions are automatically awaited. ### Parameters - **runtime** (runtime()) - Required - The server process running the JS context. - **fn_name** (String.t()) - Required - The name of the global JS function to call. - **args** (list()) - Optional - List of arguments to pass to the function. - **opts** (keyword()) - Optional - Options including :timeout (maximum execution time in milliseconds). ### Response - **js_result()** ({:ok, term()} | {:error, QuickBEAM.JSError.t()}) - The result of the function call or an error. ``` -------------------------------- ### globals(runtime, opts) Source: https://hexdocs.pm/quickbeam Lists global names defined in the JavaScript context. ```APIDOC ## globals(runtime, opts) ### Description List global names defined in the JS context. By default returns all globalThis property names. ### Parameters - **runtime** (runtime()) - Required - The QuickBEAM runtime instance. - **opts** (keyword()) - Optional - Options including user_only: true to exclude JS builtins and QuickBEAM internals. ### Returns - **{:ok, [String.t()]} | {:error, QuickBEAM.JSError.t()}** - A list of global names or an error. ``` -------------------------------- ### QuickBEAM Module Functions Source: https://hexdocs.pm/quickbeam Core functions for managing JavaScript runtimes, evaluating code, and interacting with the JS context. ```APIDOC ## QuickBEAM.start(opts \\ []) ### Description Starts a new JavaScript runtime as a GenServer. ### Parameters - **opts** (Keyword list) - Optional - Configuration options including :name, :id, :handlers, :script, :memory_limit, :max_stack_size, :wasm_stack_size, :wasm_heap_size, :max_convert_depth, and :max_convert_nodes. ## QuickBEAM.eval(runtime, code, opts \\ []) ### Description Evaluates JavaScript code within the specified runtime and returns the result. ## QuickBEAM.call(runtime, fn_name, args \\ [], opts \\ []) ### Description Calls a global JavaScript function by name within the runtime. ## QuickBEAM.stop(runtime) ### Description Stops a runtime and frees its resources. ## QuickBEAM.dom_find(runtime, selector) ### Description Finds the first element matching a CSS selector in the runtime's DOM, returning a Floki-compatible tuple. ## QuickBEAM.set_global(runtime, name, value) ### Description Sets a JavaScript global variable from Elixir. ``` -------------------------------- ### Retrieve runtime diagnostics Source: https://hexdocs.pm/quickbeam Returns a map containing registered handlers, memory statistics, and the count of JS globals. ```elixir @spec info(runtime()) :: map() ``` -------------------------------- ### Serialize DOM to HTML Source: https://hexdocs.pm/quickbeam Serializes the entire DOM tree to an HTML string. ```elixir @spec dom_html(runtime()) :: {:ok, String.t()} ``` ```elixir {:ok, rt} = QuickBEAM.start() QuickBEAM.eval(rt, "document.body.innerHTML = '

Hello

'") {:ok, html} = QuickBEAM.dom_html(rt) ``` -------------------------------- ### dom_html(runtime) Source: https://hexdocs.pm/quickbeam Serializes the entire DOM tree to an HTML string. ```APIDOC ## dom_html(runtime) ### Description Serializes the entire DOM tree to an HTML string. ### Signature `dom_html(runtime()) :: {:ok, String.t()}` ### Example ```elixir {:ok, rt} = QuickBEAM.start() QuickBEAM.eval(rt, "document.body.innerHTML = '

Hello

'") {:ok, html} = QuickBEAM.dom_html(rt) ``` ``` -------------------------------- ### Compile JavaScript to bytecode Source: https://hexdocs.pm/quickbeam Converts JavaScript source code into a binary format for precompilation or caching. ```elixir @spec compile(runtime(), String.t()) :: {:ok, binary()} | {:error, QuickBEAM.JSError.t()} ``` -------------------------------- ### Load an ES module Source: https://hexdocs.pm/quickbeam Loads and registers an ES module string into the runtime. ```elixir @spec load_module(runtime(), String.t(), String.t()) :: :ok | {:error, String.t()} ``` ```elixir iex> {:ok, rt} = QuickBEAM.start() iex> code = "export function add(a, b) { return a + b; }" iex> QuickBEAM.load_module(rt, "math", code) :ok iex> QuickBEAM.stop(rt) :ok ``` -------------------------------- ### QuickBEAM.send_message/2 Source: https://hexdocs.pm/quickbeam Sends a message to the JavaScript runtime's message handler. ```APIDOC ## QuickBEAM.send_message(runtime, message) ### Description Send a message to the runtime's JS handler. The message is delivered to the callback registered via `Beam.onMessage` in JS. ### Parameters - **runtime** (runtime()) - Required - The runtime process identifier. - **message** (term()) - Required - The message to send. ``` -------------------------------- ### dom_find_all(runtime, selector) Source: https://hexdocs.pm/quickbeam Finds all elements matching a CSS selector in the runtime's DOM. ```APIDOC ## dom_find_all(runtime, selector) ### Description Find all elements matching a CSS selector in the runtime's DOM. Returns a list of Floki-compatible `{tag, attrs, children}` tuples. ### Signature `dom_find_all(runtime(), String.t()) :: {:ok, list()}` ### Example ```elixir {:ok, rt} = QuickBEAM.start() QuickBEAM.eval(rt, ~s[document.body.innerHTML = '']) {:ok, items} = QuickBEAM.dom_find_all(rt, "li") length(items) # => 2 ``` ``` -------------------------------- ### coverage(runtime) Source: https://hexdocs.pm/quickbeam Retrieves the current JavaScript code coverage data for a runtime. ```APIDOC ## coverage(runtime) ### Description Get current JS coverage data for a runtime. Coverage must be enabled via QuickBEAM.Cover. ### Parameters - **runtime** (runtime()) - Required - The server process. ### Response - **result** ({:ok, map()} | {:error, term()}) - A map where keys are filenames and values are maps of line numbers to hit counts. ``` -------------------------------- ### QuickBEAM.reset/1 Source: https://hexdocs.pm/quickbeam Resets the JavaScript runtime to a fresh state, clearing all global variables and functions. ```APIDOC ## QuickBEAM.reset(runtime) ### Description Reset the runtime to a fresh JS context. Clears all state and functions. ### Parameters - **runtime** (runtime()) - Required - The runtime process identifier. ``` -------------------------------- ### disasm(bytecode) Source: https://hexdocs.pm/quickbeam Disassembles precompiled bytecode into a structured format. ```APIDOC ## disasm(bytecode) ### Description Disassemble precompiled bytecode into a %QuickBEAM.Bytecode{} struct. Does not require a running runtime. ### Parameters - **bytecode** (binary()) - Required - The compiled bytecode binary. ### Response - **result** ({:ok, QuickBEAM.Bytecode.t()} | {:error, String.t()}) - The disassembled bytecode struct or an error. ``` -------------------------------- ### Retrieve JavaScript coverage data Source: https://hexdocs.pm/quickbeam Fetches execution coverage metrics for the runtime, provided coverage was enabled. ```elixir @spec coverage(runtime()) :: {:ok, map()} | {:error, term()} ``` -------------------------------- ### Stop a Quickbeam runtime Source: https://hexdocs.pm/quickbeam Terminates the specified runtime and frees its resources. Returns :ok upon success. ```elixir @spec stop(runtime()) :: :ok ``` -------------------------------- ### dom_find(runtime, selector) Source: https://hexdocs.pm/quickbeam Finds the first element matching a CSS selector in the runtime's DOM. ```APIDOC ## dom_find(runtime, selector) ### Description Find the first element matching a CSS selector in the runtime's DOM. Returns the element as a Floki-compatible `{tag, attrs, children}` tuple, or `nil` if no match is found. ### Signature `dom_find(runtime(), String.t()) :: {:ok, tuple() | nil}` ### Example ```elixir {:ok, rt} = QuickBEAM.start() QuickBEAM.eval(rt, "document.body.innerHTML = '

Hello

'") {:ok, {"p", [{"class", "intro"}], ["Hello"]}} = QuickBEAM.dom_find(rt, "p.intro") ``` ``` -------------------------------- ### eval(runtime, code, opts) Source: https://hexdocs.pm/quickbeam Evaluates JavaScript code and returns the result, with support for top-level await. ```APIDOC ## eval(runtime, code, opts) ### Description Evaluate JavaScript code and return the result. Top-level `await` is supported. ### Signature `eval(runtime(), String.t(), keyword()) :: js_result()` ### Options - **timeout** (integer) - Maximum execution time in milliseconds. If exceeded, execution is interrupted. - **vars** (map) - A map of variable names to values, available in the code as globals. ### Example ```elixir {:ok, rt} = QuickBEAM.start() QuickBEAM.eval(rt, "40 + 2") # => {:ok, 42} QuickBEAM.eval(rt, "name.toUpperCase()", vars: %{"name" => "quickbeam"}) # => {:ok, "QUICKBEAM"} ``` ``` -------------------------------- ### Define js_result and runtime types Source: https://hexdocs.pm/quickbeam Type definitions for JavaScript execution results and the runtime server reference. ```elixir @type js_result() :: {:ok, term()} | {:error, QuickBEAM.JSError.t()} ``` ```elixir @type runtime() :: GenServer.server() ``` -------------------------------- ### disasm(runtime, code) Source: https://hexdocs.pm/quickbeam Compiles JavaScript source code and disassembles the resulting bytecode. ```APIDOC ## disasm(runtime, code) ### Description Compiles JavaScript source and disassembles the resulting bytecode. ### Signature `disasm(runtime(), String.t()) :: {:ok, QuickBEAM.Bytecode.t()} | {:error, term()}` ### Example ```elixir {:ok, %QuickBEAM.Bytecode{cpool: [%QuickBEAM.Bytecode{name: "add"}]}} = QuickBEAM.disasm(rt, "function add(a, b) { return a + b }") ``` ``` -------------------------------- ### compile(runtime, code) Source: https://hexdocs.pm/quickbeam Compiles JavaScript source code into bytecode without executing it. ```APIDOC ## compile(runtime, code) ### Description Compile JavaScript source to bytecode without executing it. Returns bytecode that can be loaded into any runtime. ### Parameters - **runtime** (runtime()) - Required - The server process. - **code** (String.t()) - Required - The JavaScript source code to compile. ### Response - **result** ({:ok, binary()} | {:error, QuickBEAM.JSError.t()}) - The compiled bytecode or an error. ``` -------------------------------- ### Disassemble bytecode or source code Source: https://hexdocs.pm/quickbeam Parses bytecode or source code into a structured representation without requiring a persistent runtime. ```elixir @spec disasm(binary()) :: {:ok, QuickBEAM.Bytecode.t()} | {:error, String.t()} ``` ```elixir {:ok, bytecode} = QuickBEAM.compile(rt, "function add(a, b) { return a + b }") {:ok, %QuickBEAM.Bytecode{}} = QuickBEAM.disasm(bytecode) ``` ```elixir {:ok, %QuickBEAM.Bytecode{}} = QuickBEAM.disasm(rt, "function add(a, b) { return a + b }") ``` -------------------------------- ### Find all matching DOM elements Source: https://hexdocs.pm/quickbeam Retrieves a list of all elements matching a CSS selector as Floki-compatible tuples. ```elixir @spec dom_find_all(runtime(), String.t()) :: {:ok, list()} ``` ```elixir {:ok, rt} = QuickBEAM.start() QuickBEAM.eval(rt, ~s[document.body.innerHTML = '']) {:ok, items} = QuickBEAM.dom_find_all(rt, "li") length(items) # => 2 ``` -------------------------------- ### Inject Variables into JavaScript Source: https://hexdocs.pm/quickbeam Passes a map of variables to be available as globals during JavaScript execution. ```elixir QuickBEAM.eval(rt, "name.toUpperCase()", vars: %{"name" => "quickbeam"}) # => {:ok, "QUICKBEAM"} QuickBEAM.eval(rt, "items.map(i => i.price * i.qty).reduce((a, b) => a + b, 0)", vars: %{"items" => [%{"price" => 10, "qty" => 3}, %{"price" => 5, "qty" => 2}]}) # => {:ok, 40} ``` -------------------------------- ### Configure Evaluation Timeout Source: https://hexdocs.pm/quickbeam Sets a maximum execution time in milliseconds for JavaScript evaluation. ```elixir QuickBEAM.eval(rt, "while(true) {}", timeout: 1000) # => {:error, %QuickBEAM.JSError{message: "interrupted", ...}} ``` -------------------------------- ### QuickBEAM.set_global/3 Source: https://hexdocs.pm/quickbeam Sets a global variable within the JavaScript runtime from Elixir. ```APIDOC ## QuickBEAM.set_global(runtime, name, value) ### Description Set a JS global variable from Elixir. The value is converted using the standard BEAM to JS conversion. ### Parameters - **runtime** (runtime()) - Required - The runtime process identifier. - **name** (String.t()) - Required - The name of the global variable. - **value** (term()) - Required - The value to assign. ``` -------------------------------- ### Call global JavaScript functions Source: https://hexdocs.pm/quickbeam Executes a global JavaScript function by name, automatically awaiting promises and converting arguments. ```elixir @spec call(runtime(), String.t(), list(), keyword()) :: js_result() ``` ```elixir iex> {:ok, rt} = QuickBEAM.start() iex> QuickBEAM.eval(rt, "function add(a, b) { return a + b }") iex> QuickBEAM.call(rt, "add", [2, 3]) {:ok, 5} iex> QuickBEAM.stop(rt) :ok ``` -------------------------------- ### Find single DOM element Source: https://hexdocs.pm/quickbeam Queries the live DOM tree for the first element matching a CSS selector, returning it as a Floki-compatible tuple. ```elixir @spec dom_find(runtime(), String.t()) :: {:ok, tuple() | nil} ``` ```elixir {:ok, rt} = QuickBEAM.start() QuickBEAM.eval(rt, "document.body.innerHTML = '

Hello

'") {:ok, {"p", [{"class", "intro"}], ["Hello"]}} = QuickBEAM.dom_find(rt, "p.intro") ``` -------------------------------- ### dom_attr(runtime, selector, attr_name) Source: https://hexdocs.pm/quickbeam Retrieves an attribute value from the first element matching a CSS selector. ```APIDOC ## dom_attr(runtime, selector, attr_name) ### Description Get an attribute value from the first element matching a CSS selector. Returns `nil` if the element or attribute is not found. ### Signature `dom_attr(runtime(), String.t(), String.t()) :: {:ok, String.t() | nil}` ### Example ```elixir {:ok, rt} = QuickBEAM.start() QuickBEAM.eval(rt, ~s[document.body.innerHTML = 'link']) {:ok, "/page"} = QuickBEAM.dom_attr(rt, "a", "href") ``` ``` -------------------------------- ### Evaluate JavaScript Code Source: https://hexdocs.pm/quickbeam Evaluates JavaScript code within the runtime, supporting top-level await. ```elixir @spec eval(runtime(), String.t(), keyword()) :: js_result() ``` ```elixir iex> {:ok, rt} = QuickBEAM.start() iex> QuickBEAM.eval(rt, "40 + 2") {:ok, 42} iex> QuickBEAM.eval(rt, "await Promise.all([1, 2].map(x => Promise.resolve(x)))") {:ok, [1, 2]} iex> QuickBEAM.stop(rt) :ok ``` -------------------------------- ### stop(runtime) Source: https://hexdocs.pm/quickbeam Stops a specified runtime and releases its associated resources. ```APIDOC ## stop(runtime) ### Description Stops a runtime and free its resources. ### Signature `stop(runtime()) :: :ok` ### Parameters - **runtime** (runtime()) - Required - The runtime instance to be stopped. ``` -------------------------------- ### Send a message to the JS runtime Source: https://hexdocs.pm/quickbeam Delivers a message to the handler registered via Beam.onMessage in JavaScript. ```elixir @spec send_message(runtime(), term()) :: :ok ``` -------------------------------- ### Reset the JavaScript runtime Source: https://hexdocs.pm/quickbeam Clears all state and functions within the JS context. ```elixir @spec reset(runtime()) :: :ok | {:error, String.t()} ``` ```elixir iex> {:ok, rt} = QuickBEAM.start() iex> QuickBEAM.eval(rt, "globalThis.x = 42") iex> QuickBEAM.reset(rt) :ok iex> QuickBEAM.eval(rt, "typeof x") {:ok, "undefined"} iex> QuickBEAM.stop(rt) :ok ``` -------------------------------- ### dom_text(runtime, selector) Source: https://hexdocs.pm/quickbeam Extracts text content from the first element matching a CSS selector. ```APIDOC ## dom_text(runtime, selector) ### Description Extracts text content from the first element matching a CSS selector. ### Signature `dom_text(runtime(), String.t()) :: {:ok, String.t()}` ### Example ```elixir {:ok, rt} = QuickBEAM.start() QuickBEAM.eval(rt, "document.body.innerHTML = '

Title

'") {:ok, "Title"} = QuickBEAM.dom_text(rt, "h1") ``` ``` -------------------------------- ### Disassemble JavaScript code Source: https://hexdocs.pm/quickbeam Compiles JavaScript source code and returns the resulting bytecode structure. ```elixir @spec disasm(runtime(), String.t()) :: {:ok, QuickBEAM.Bytecode.t()} | {:error, term()} ``` ```elixir {:ok, %QuickBEAM.Bytecode{cpool: [%QuickBEAM.Bytecode{name: "add"}]}} = QuickBEAM.disasm(rt, "function add(a, b) { return a + b }") ``` -------------------------------- ### List global names Source: https://hexdocs.pm/quickbeam Retrieves a list of global names defined in the JavaScript context. Use the user_only option to filter out built-in properties. ```elixir @spec globals( runtime(), keyword() ) :: {:ok, [String.t()]} | {:error, QuickBEAM.JSError.t()} ``` ```elixir {:ok, all} = QuickBEAM.globals(rt) # ["Array", "Boolean", "Buffer", "Object", "console", "myVar", ...] {:ok, mine} = QuickBEAM.globals(rt, user_only: true) # ["myVar", "myFunc"] ``` -------------------------------- ### Evaluate TypeScript code Source: https://hexdocs.pm/quickbeam Executes TypeScript code by transforming it to JavaScript. Requires an active runtime instance. ```elixir @spec eval_ts(runtime(), String.t(), keyword()) :: js_result() ``` ```elixir iex> {:ok, rt} = QuickBEAM.start() iex> QuickBEAM.eval_ts(rt, "const x: number = 40 + 2; x") {:ok, 42} iex> QuickBEAM.stop(rt) :ok ``` -------------------------------- ### Retrieve DOM attribute values Source: https://hexdocs.pm/quickbeam Fetches the value of a specific attribute from the first element matching the provided CSS selector. ```elixir @spec dom_attr(runtime(), String.t(), String.t()) :: {:ok, String.t() | nil} ``` ```elixir {:ok, rt} = QuickBEAM.start() QuickBEAM.eval(rt, ~s[document.body.innerHTML = 'link']) {:ok, "/page"} = QuickBEAM.dom_attr(rt, "a", "href") ``` -------------------------------- ### get_global(runtime, name) Source: https://hexdocs.pm/quickbeam Retrieves the value of a JavaScript global variable safely by accessing it as a property. ```APIDOC ## get_global(runtime, name) ### Description Get the value of a JS global. Works like eval(rt, "name") but safer — the name is accessed as a property, not evaluated as code. ### Parameters - **runtime** (runtime()) - Required - The QuickBEAM runtime instance. - **name** (String.t()) - Required - The name of the global variable to retrieve. ### Returns - **js_result()** - The value converted to Elixir terms. For objects, returns a map of enumerable own properties; for functions, returns a map with metadata. ``` -------------------------------- ### Set a global variable in the JS runtime Source: https://hexdocs.pm/quickbeam Sets a JS global variable from Elixir using standard BEAM to JS conversion. ```elixir @spec set_global(runtime(), String.t(), term()) :: :ok ``` ```elixir QuickBEAM.set_global(rt, "config", %{"theme" => "dark", "limit" => 100}) {:ok, "dark"} = QuickBEAM.eval(rt, "config.theme") QuickBEAM.set_global(rt, "items", [1, 2, 3]) {:ok, 3} = QuickBEAM.eval(rt, "items.length") ``` -------------------------------- ### Defining JS Handlers Source: https://hexdocs.pm/quickbeam Registers Elixir functions that can be invoked from JavaScript using Beam.call or Beam.callSync. ```elixir iex> {:ok, rt} = QuickBEAM.start(handlers: %{ ...> "greet" => fn [name] -> "Hello, #{name}!" end ...> }) iex> QuickBEAM.eval(rt, ~s[Beam.callSync("greet", "world")]) {:ok, "Hello, world!"} iex> QuickBEAM.stop(rt) :ok ``` -------------------------------- ### Extract DOM Text Content Source: https://hexdocs.pm/quickbeam Extracts text content from the first element matching a CSS selector. ```elixir @spec dom_text(runtime(), String.t()) :: {:ok, String.t()} ``` ```elixir {:ok, rt} = QuickBEAM.start() QuickBEAM.eval(rt, "document.body.innerHTML = '

Title

'") {:ok, "Title"} = QuickBEAM.dom_text(rt, "h1") ``` -------------------------------- ### eval_ts(runtime, ts_code, opts) Source: https://hexdocs.pm/quickbeam Evaluates TypeScript code by transforming it to JavaScript and executing it within the provided runtime. ```APIDOC ## eval_ts(runtime, ts_code, opts) ### Description Evaluates TypeScript code by transforming it to JavaScript first. This is equivalent to calling OXC.transform!/2 followed by eval/3 in a single operation. ### Parameters - **runtime** (runtime()) - Required - The QuickBEAM runtime instance. - **ts_code** (String.t()) - Required - The TypeScript source code string. - **opts** (keyword()) - Optional - Options accepted by eval/3, such as :timeout. ### Returns - **js_result()** - The result of the evaluation. ``` -------------------------------- ### Retrieve global variables Source: https://hexdocs.pm/quickbeam Accesses a JavaScript global variable safely by property name. Returns the value converted to Elixir terms. ```elixir @spec get_global(runtime(), String.t()) :: js_result() ``` ```elixir QuickBEAM.get_global(rt, "myVar") {:ok, 42} QuickBEAM.get_global(rt, "myObj") {:ok, %{"x" => 1, "y" => 2}} QuickBEAM.get_global(rt, "nonexistent") {:ok, nil} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.