Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A9T9 RPA buildInterpreter

From Leeroopedia
Knowledge Sources
Domains Scripting_API, Sandboxing
Last Updated 2026-10-22 00:00 GMT

Overview

Concrete tool for constructing a JS-Interpreter sandbox instance with the `uiv.*` API injected, provided by the Ui.Vision script runner.

Description

The buildInterpreter function (`src/modules/script_runner.js`) creates a vendored JS-Interpreter instance for executing transpiled ES5 macro code in a controlled sandbox. The JS-Interpreter is a synchronous, step-by-step interpreter that allows the UI to remain responsive (the run loop calls `interpreter.step()` in a timer-driven loop, enabling pause/resume and breakpoint support).

During construction, `buildInterpreter` injects the full `uiv.*` API into the interpreter's global object. It also injects:

  • `__uiv_bridge`: an async function bridge that dispatches operations from the sandbox to the host (element finding, input, OCR, etc.) and returns results
  • `__uiv_pause`: a sleep/wait function
  • `__uiv_exit`: a function to request early script termination
  • `__uiv_get`: a variable getter (for `!` system variables like `!TIMEOUT_WAIT`)
  • `__uiv_call_data`: initial arguments and context for the script

The `runScript` function is the high-level entry point that calls `buildInterpreter`, manages the run lifecycle (state, trails, CDP attach), and drives the interpreter step loop to completion.

Usage

Call `buildInterpreter` to create a sandboxed interpreter for transpiled ES5 code. Use `runScript` for the complete execution lifecycle — it handles setup, the step loop, error handling, and teardown.

Code Reference

Source Location

  • Repository: A9T9/RPA
  • File: src/modules/script_runner.js
  • Lines: L8086-L8260 (buildInterpreter), L8261-L8698 (runScript)

Signature

function buildInterpreter(code: string, opts?: object): Interpreter

export async function runScript(
  code: string,
  opts?: object
): Promise<RunScriptResult>

Import

import { runScript } from '@/modules/script_runner'
// buildInterpreter is internal, used by runScript

I/O Contract

Inputs

Name Type Required Description
code string Yes Transpiled ES5 script string
opts object No Execution options (store, breakpoints, variables, macroId, tabId, name, etc.)

Outputs

Name Type Description
interpreter Interpreter JS-Interpreter instance with uiv.* API injected
RunScriptResult object Execution result: status (ok/error), error, errorLine, return value

Usage Examples

Run a JS Script Macro

import { runScript } from '@/modules/script_runner'

const result = await runScript(transpiledCode, {
  macroId: 'my-macro-id',
  name: 'Login Test',
  tabId: 42
})

if (result.status === 'ok') {
  console.log('Script completed successfully')
} else {
  console.error(`Script failed at line ${result.errorLine}: ${result.error}`)
}

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment