System & Automation
## g.workers.* — Queue Workers
Section titled “## g.workers.* — Queue Workers”Manage concurrent worker pools for batch processing. See Queue Workers for full details.
| Method | Signature | Async | Description |
|---|---|---|---|
start | (options) | No | Launch worker pools |
stop | (queueName?) | No | Stop workers (all or by queue) |
pause | () | No | Pause all dequeue operations |
resume | () | No | Resume dequeue operations |
status | () → WorkerPoolStatus[] | No | Get status of all pools |
WorkerStartOptions:
{ clearTabs?: boolean layout?: "horizontal" | "vertical" | "quad" workers: WorkerPoolOptions[]}WorkerPoolOptions:
{ queue: string script: string concurrency?: number throttle?: { requestsPerMinute?: number } dequeue?: string requiresWorkflowEnvelope?: boolean}Set requiresWorkflowEnvelope: true for workflow-owned queues that must only process items linked to a Workflow Ledger run/item envelope.
## g.worker.* — Worker Context
Section titled “## g.worker.* — Worker Context”Available only inside worker scripts.
| Method | Signature | Async | Description |
|---|---|---|---|
getContext | () → WorkerContext | No | Get the current item, tab ID, and queue name |
WorkerContext:
{ item: QueueItem tabId: string queueName: string}## g.network.* — Network Traffic
Section titled “## g.network.* — Network Traffic”Access captured HTTP traffic. Capture must be enabled (it is by default).
| Method | Signature | Async | Description |
|---|---|---|---|
search | (query?, options?) → TrafficEntryInfo[] | No | Search captured traffic |
getById | (id) → TrafficEntryInfo | null | No | Get a specific traffic entry |
getResponseBody | (id) → string | null | No | Get the response body |
getRequestBody | (id) → string | null | No | Get the request body |
count | () → number | No | Count captured entries |
clear | () | No | Clear all captured traffic |
enable | () | No | Enable traffic capture |
disable | () | No | Disable traffic capture |
isEnabled | () → boolean | No | Check if capture is enabled |
waitForRequest | (urlPattern, options?) → Promise<TrafficEntryInfo> | Yes | Wait for a matching request |
NetworkSearchOptions:
{ method?: string // "GET", "POST", etc. statusMin?: number statusMax?: number contentType?: string tabId?: string limit?: number // default: 100 offset?: number // default: 0 sort?: string // timestamp, url, status, size, duration, method order?: string // "asc" or "desc" (default)}WaitForRequestOptions:
{ method?: string timeout?: number // default: 30000ms}Example
Section titled “Example”async function main() { await g.nav.navigateToUrl("https://api.example.com/data");
// Wait for the API response const entry = await g.network.waitForRequest("api.example.com/data"); const body = g.network.getResponseBody(entry.id); const data = JSON.parse(body); g.log("Got " + data.items.length + " items");}## g.history.* — Navigation History
Section titled “## g.history.* — Navigation History”| Method | Signature | Async | Description |
|---|---|---|---|
search | (query?, options?) → NavigationEntryInfo[] | No | Search navigation history |
count | () → number | No | Count history entries |
clear | () | No | Clear all history |
HistorySearchOptions:
{ tabId?: string limit?: number // default: 100 offset?: number // default: 0 sort?: string // "timestamp" (default), "url", "status" order?: string // "asc" or "desc" (default)}## g.robots.* — Robots.txt Compliance
Section titled “## g.robots.* — Robots.txt Compliance”Automatic robots.txt checking for scripted automation. Enabled by default.
| Method | Signature | Async | Description |
|---|---|---|---|
isAllowed | (url) → Promise<boolean> | Yes | Check if a URL is allowed by robots.txt |
getCrawlDelay | (url) → Promise<number | null> | Yes | Get the crawl-delay for a domain |
disable | () | No | Disable robots.txt checking for this script |
enable | () | No | Re-enable robots.txt checking |
## g.workflows.* — Workflows
Section titled “## g.workflows.* — Workflows”Inspect and switch between workflows within a workspace.
| Method | Signature | Async | Description |
|---|---|---|---|
getActive | () → WorkflowInfo | null | No | Get the active workflow’s name and path |
list | () → WorkflowListItem[] | No | List all workflows in the workspace |
switch | (name) | No | Switch to a workflow (fire-and-forget, happens on UI thread) |
WorkflowInfo:
{ name: string // workflow name path: string // absolute path to workflow folder}WorkflowListItem:
{ name: string enabled: boolean hasEvents: boolean // has events.json triggers hasWorkers: boolean // has workers.json config hasTools: boolean // has tools/ directory hasViews: boolean // has views/ directory scriptCount: number // number of script files}## g.trigger.* — Event Trigger Context
Section titled “## g.trigger.* — Event Trigger Context”Available inside scripts executed by event triggers. Returns metadata about why the script was invoked.
| Method | Signature | Async | Description |
|---|---|---|---|
getContext | () → TriggerContext | No | Get event data for the current trigger execution |
TriggerContext:
{ event: string // "url-match", "page-loaded", "tab-created", "tab-closed", // "tab-activated", "external-queue", "dom-mutation" tabId?: string // browser tab associated with the event url?: string // page URL at the time of the event timestamp: string // ISO 8601 pattern?: string // URL pattern that matched (url-match only)
// dom-mutation fields: oldValue?: string // previous value newValue?: string // new value attribute?: string // changed attribute name (null for text changes) mutationType?: string // "characterData", "attributes", or "childList" selector?: string // CSS selector that matched changes?: object[] // array of mutations (buffer strategy only)}Example
Section titled “Example”async function main() { const ctx = g.trigger.getContext();
if (ctx.event === "url-match") { g.log("Matched " + ctx.pattern + " on " + ctx.url); }
if (ctx.event === "dom-mutation") { g.log(ctx.selector + " changed: " + ctx.oldValue + " → " + ctx.newValue); }}