Utilities (upcoming)
Available in version 1.1.72 (not yet live).
Add delays and write logs.
API zw.delay()
, zw.log()
, zw.logTemp()
await zw.log("Starting run");
await zw.delay({ min: 1500, max: 2500 }); // randomized delay 1.5–2.5s
At a Glance
await zw.delay({ min: "number", max?: "number" })
→ pauses formin
(ms); ifmax
(ms) is provided andmax > min
, the delay is randomized betweenmin
andmax
await zw.log(...values: any)
→ like console.log, logs comma-separated valuesawait zw.log({ message: any, status?: "success" | "fail" | "warning", tag? })
→ logs with custom stylingawait zw.logTemp(...values: any)
await zw.logTemp({ message, status?: "success" | "fail" | "warning", tag? })
→ same aszw.log(...)
but not persisted to the run report.
Examples
// Structured status logs (styled in the UI)
await zw.log({ message: "Logged in", status: "success", tag: "auth" });
await zw.log({ message: "Slow response detected", status: "warning", tag: "network" });
await zw.log({ message: "Failed to submit form", status: "fail", tag: "checkout" });
// Log objects, arrays, and functions — no manual stringify needed
const payload = { id: 42, items: [1, 2, 3] };
const helper = (x) => x * 2;
await zw.log("Logging objects, arrays, functions", payload, helper);
// Exact wait with only 'min'
await zw.delay({ min: 1000 }); // exactly 1s, no randomized delay
await zw.log("Waited for exactly 1s");
// @zw-run-locally
// Dynamic backoff based on state
const state = zw.state.access();
state.retryCount = (state.retryCount ?? 0) + 1;
const backoffMs = Math.min(5000, 500 * state.retryCount);
await zw.log("Retry:", state.retryCount, "waiting:", backoffMs);
await zw.delay({ min: backoffMs });
// Live-only logging of secrets (never persisted to the run report)
const token = await zw.deviceStorage.get("auth_token");
await zw.logTemp("Auth token received", token);
// Structured live-only (styled in running log)
await zw.logTemp({ message: token, status: "warning", tag: "debug_auth" });
// Try/catch with styled fail log
try {
// do something that may throw
} catch (err) {
await zw.log({
message: `Action failed: ${err?.message}`,
status: "fail",
tag: "error"
});
}
Notes
Delay is always async.
zw.delay()
must be awaited in both local and browser runs. Always useawait
.Log async behavior. In the browser,
zw.log(...)
andzw.logTemp(...)
are async — useawait
. When Write JS code runs locally,await
is optional. The examples useawait
for consistency.Size limits. The persistent message saved to the run report is capped at ~500 characters. The running log view shows up to ~500,000 characters. Longer inputs do not throw but are truncated.
Avoid secrets. Prefer
zw.logTemp(...)
for sensitive data that you don’t want persisted in the run report.
Last updated
Was this helpful?