hubcap run

Execute JavaScript from a file in the page context.

When to use

Execute JavaScript from a file in the page context. The file contents are read and evaluated as a single expression. Use eval for inline expressions instead of loading a file.

Usage

hubcap run <file>

Arguments

ArgumentTypeRequiredDescription
filestringYesPath to a .js file to execute

Flags

None.

Output

FieldTypeDescription
filestringPath to the executed file
valueanyThe returned value from the script
{"file":"script.js","value":42}

Errors

ConditionExit codeStderr
File not found1error reading file: ...
JavaScript evaluation error1error: JS exception: <message>
Chrome not connected2error: connecting to Chrome: ...
Timeout3error: timeout

Examples

Run a script:

hubcap run setup.js

Run a script and extract the result with jq:

hubcap run check.js | jq '.value'

Use a script that returns page data, then pipe into further processing:

hubcap run scrape.js | jq -r '.value[]' | sort -u > links.txt

See also

  • eval - Evaluate an inline JavaScript expression
  • evalframe - Evaluate JavaScript in a specific frame