hubcap waitfn

Wait for a JavaScript expression to return a truthy value.

When to use

Use waitfn to block until a JavaScript expression evaluates to a truthy value. Use for complex conditions not covered by wait or waittext.

Usage

hubcap waitfn <expression> [--timeout <duration>]

Arguments

ArgumentTypeRequiredDescription
expressionstringYesJavaScript expression to evaluate until truthy

Flags

FlagTypeDefaultDescription
—timeoutduration30sMaximum wait time

Output

FieldTypeDescription
completedboolWhether the expression returned truthy
expressionstringThe expression that was evaluated
{"completed":true,"expression":"window.appReady === true"}

Errors

ConditionExit codeStderr
Missing expression argument1usage: hubcap waitfn <expression> [--timeout <duration>]
Chrome not connected2error: connecting to Chrome: ...
Expression not truthy within timeout3error: timeout

Examples

Wait for an app-level ready flag:

hubcap waitfn 'window.appReady === true'

Wait for a specific array length:

hubcap waitfn 'document.querySelectorAll(".item").length >= 10' --timeout 20s

Navigate and wait for a custom condition (chaining):

hubcap goto --wait https://example.com && hubcap waitfn 'window.dataLoaded'

See also

  • wait - Wait for an element by CSS selector
  • waittext - Wait for text content to appear on the page
  • eval - Evaluate a JavaScript expression
  • waitgone - Wait for an element to be removed from the DOM