Appearance
Script Web APIs
These globals are available in Pre-Request and Post-Request scripts. They are explicit APIs in the isolated runtime, not access to Node.js, the browser DOM or the filesystem. All operations remain subject to the script deadline and limits.
Console output
console.log(...values), console.info(...values), console.warn(...values), console.error(...values) and console.debug(...values) return undefined and append a local output entry. They do not throw just because their level is error.
Open Console at the bottom of the request workspace to see entries with their level, phase and source, in both the browser and desktop app. The bar starts collapsed and shows a small orange dot when output is available; the dot is absent when there are no entries. Output appears in a read-only editor where you can select and copy text; it does not accept commands. Drag its upper divider to resize the open panel, or focus the divider and use Arrow Up/Down (Home/End for minimum/maximum height). Escape closes the panel and returns focus to Console. Output survives a script failure and is cleared by the next Send or by closing the tab. It is not saved, synchronized, or forwarded to the developer console or backend logs.
Arguments are formatted immediately: strings as text, objects as JSON, errors as name/message. Circular or otherwise unserializable values use a placeholder. Formatting tokens such as %s, groups, tables, assertions and console timers are not implemented. At most 200 entries are retained per Send, each limited to 2000 characters; additional output is ignored. Values are not automatically redacted: only log information you want visible in this request tab.
js
console.info('Running', elc.context.source.name);
console.log({ tenant: elc.variables.get('tenantId') });Timers
setTimeout(callback: Function, delayMs = 0, ...args): number schedules a callback and returns its timer ID. clearTimeout(id: number): void cancels a scheduled callback; unknown IDs do nothing. String callbacks are rejected. Delays are nonnegative milliseconds; a zero delay still runs asynchronously. Timers are not precise scheduling guarantees.
The runner waits for pending callbacks and promises returned by callbacks before finishing the script and committing its writes. A callback error fails the script. Clearing a timer prevents a callback that has not started; it does not interrupt an already-running callback. A callback that has started remains subject to the script abort and deadline. Cancellation, failure or timeout discards remaining callbacks.
js
await new Promise(resolve => setTimeout(resolve, 250));
console.log('Continue after a short delay');Timers share the script's 60-second deadline; they do not extend it. A script fetch started from a callback must be awaited or returned. Detached promises are not a background-task API. setInterval and clearInterval are not provided. At most 64 timers may be pending, and each scheduled timer uses one of the script's 64 asynchronous host calls (also shared with fetch, digest, initialization and commit).
URL
new URL(input: string | URL, base?: string | URL) parses a URL. Relative inputs need a valid base; invalid inputs throw. Parsing does not perform network access. The constructor accepts schemes that may still be rejected when used in fetch.
| Member | Behavior |
|---|---|
href | Read/write full serialized URL |
protocol | Read/write scheme, including the colon |
username, password | Read/write encoded credentials |
host, hostname, port | Read/write host components |
pathname | Read/write path |
search | Read/write query, including a leading ? when nonempty |
hash | Read/write fragment, including a leading # when nonempty |
origin | Read-only serialized origin |
searchParams | Read-only reference to a mutable, linked URLSearchParams object |
toString(): string, toJSON(): string | Return the serialized URL |
URL.canParse(input, base?): boolean | Whether construction succeeds |
URL.parse(input, base?): URL or null | Construct, or return null for invalid input |
Changing searchParams updates the URL, and assigning search or href updates the existing searchParams view. Object-URL creation/revocation is not available.
js
const url = new URL('/token', 'https://example.test');
url.searchParams.set('tenant', elc.variables.get('tenantId'));
const response = await fetch(url);URLSearchParams
new URLSearchParams(input = '') accepts query text, a record, an iterable of name/value pairs, or another URLSearchParams. Names and values are strings. The methods follow form-query encoding: spaces become +, and reserved and non-ASCII characters are percent-encoded.
| Member | Signature and effect |
|---|---|
size | Read-only count of pairs, including duplicates |
append(name, value): void | Add a pair without removing duplicates |
set(name, value): void | Replace values for a name with one pair |
delete(name, value?): void | Remove all matching names, or only matching name/value pairs |
has(name, value?): boolean | Check for a name or name/value pair |
get(name): string or null | First matching value, or null |
getAll(name): string[] | All matching values; empty array if missing |
sort(): void | Stable sort by name |
toString(): string | Encoded query without a leading ? |
entries(), [Symbol.iterator]() | Iterate [name, value] pairs |
keys(), values() | Iterate names or values |
forEach(callback, thisArg?): void | Call (value, name, params) for each pair |
fetch accepts URLSearchParams as its body, serializes it and supplies application/x-www-form-urlencoded;charset=UTF-8 unless you supplied a Content-Type.
js
const response = await fetch(elc.variables.get('tokenUrl'), {
method: 'POST',
body: new URLSearchParams({
grant_type: 'client_credentials',
client_id: elc.variables.get('clientId'),
client_secret: elc.variables.get('clientSecret'),
}),
});
if (!response.ok) throw new Error('Token request failed');TextEncoder
new TextEncoder() always uses UTF-8. Its read-only encoding property is utf-8.
encode(input = ''): Uint8Arrayencodes text. Unpaired UTF-16 surrogates are replaced, unlike the strict@stablelib/utf8package's encoder.encodeInto(input: string, destination: Uint8Array): { read, written }writes complete characters into the destination.readcounts UTF-16 code units,writtencounts bytes. Bytes outside the written range remain unchanged. The destination is limited to 16384 bytes by this binding.
TextDecoder
new TextDecoder(label = 'utf-8', options = {}) uses native decoder labels and accepts boolean fatal and ignoreBOM options. Unknown labels throw. Read-only properties encoding, fatal and ignoreBOM report the selected configuration. UTF-8 is verified in both browser and desktop; other label support depends on the host runtime's native decoder.
decode(input?: ArrayBuffer | ArrayBufferView, options?: { stream?: boolean }): string decodes bytes. By default invalid sequences are replaced; fatal: true makes them throw. With stream: true, an incomplete trailing sequence is retained for the next call. Finish with decode() or a call without streaming to flush it. At most 64 decoder instances may be created per script; all are discarded at end.
js
const bytes = new TextEncoder().encode('Hello 🦌');
const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);Crypto
This is a selected Web Crypto surface, not node:crypto or the complete SubtleCrypto API. It uses the host's cryptographically secure generator and digest implementation. No insecure random fallback is used.
crypto.getRandomValues(array)
getRandomValues(array: IntegerTypedArray): same array fills the supplied view in place, respecting its offset and length. Signed/unsigned integer typed arrays, Uint8ClampedArray and BigInt integer arrays are supported. Floating-point arrays, DataView and plain arrays are rejected. More than 65536 bytes throws a QuotaExceededError. A random operation does not persist data.
crypto.randomUUID()
randomUUID(): string returns a cryptographically random version-4 UUID.
crypto.subtle.digest(algorithm, data)
digest(algorithm: string | { name: string }, data: ArrayBuffer | ArrayBufferView): Promise<ArrayBuffer> accepts SHA-1, SHA-256, SHA-384 or SHA-512 (case-insensitively). Invalid algorithms or data reject the promise. The result contains 20, 32, 48 or 64 bytes, respectively. Prefer SHA-256 or SHA-512 for new workflows. This API does not stream.
js
const bytes = new TextEncoder().encode('abc');
const digest = await crypto.subtle.digest('SHA-256', bytes);
const hex = Array.from(new Uint8Array(digest), value =>
value.toString(16).padStart(2, '0')).join('');
console.log(hex);Key import/generation, signing, verification and encryption/decryption are not provided on subtle. HMAC is available through the package catalog.
Resource bounds and lifetime
Synchronous URL, encoding, randomness and console calls use a bounded bridge: 4096 calls per script and 64 KiB of serialized JSON per request or response. Byte arrays are serialized as numbers, so the limit may be reached with fewer than 64 KiB of binary data. Encoding, decoding or digesting oversized inputs fails; use smaller decoder chunks or the in-VM packages for larger compatible operations. getRandomValues chunks its native calls internally to support its 65536-byte quota.
All objects belong to one script invocation. Timer callbacks and local console entries do not become server-side or background jobs. Native digest computation cannot be interrupted internally, but its bounded result is discarded after abort; it cannot commit script values or update the request afterward.
Related: Scripts and elc API · Package imports