hubcap evalframe

Evaluate JavaScript in a specific frame.

When to use

Use evalframe to run a JavaScript expression inside a particular iframe or frame context. Use frames to list available frame IDs first. Use eval when you need to evaluate JavaScript in the main frame only.

Usage

hubcap evalframe <frame-id> <expression>

Arguments

ArgumentTypeRequiredDescription
frame-idstringYesTarget frame identifier (use frames to list available IDs)
expressionstringYesJavaScript expression to evaluate

Flags

None.

Output

FieldTypeDescription
frameIdstringThe frame in which the expression was evaluated
typestringJavaScript type of the result (e.g. string, number, boolean, object)
valueanyThe returned value
{"frameId":"frame-123","type":"number","value":42}

Errors

ConditionExit codeStderr
JavaScript evaluation error1error: JS exception: <message>
Invalid frame ID1error: creating isolated world: ...
Chrome not connected2error: connecting to Chrome: ...
Timeout3error: timeout

Examples

Evaluate in a specific frame:

hubcap evalframe 'frame-123' 'document.title'

Get the body text of a frame:

hubcap evalframe 'frame-123' 'document.body.innerText'

Check the URL loaded in a frame:

hubcap evalframe 'frame-123' 'window.location.href'

List frames then evaluate in the first one:

hubcap frames | jq -r '.[0].id' | xargs -I{} hubcap evalframe '{}' 'document.title'

See also

  • eval - Evaluate JavaScript in the main page context
  • frames - List all frames on the page
  • run - Execute JavaScript from a file