hubcap scripts

List all script elements on the current page.

When to use

Use scripts to enumerate every <script> tag on the page, including src, type, and whether it loads asynchronously. Useful for auditing which JavaScript files are loaded or detecting unwanted third-party scripts.

Usage

hubcap scripts

Arguments

None.

Flags

None.

Output

Returns an object containing an array of script info objects.

FieldTypeDescription
scriptsarrayArray of script info objects
scripts[].srcstringThe src attribute, empty for inline scripts
scripts[].typestringThe type attribute (e.g. module, text/javascript)
scripts[].asyncbooleanWhether the script has the async attribute
scripts[].deferbooleanWhether the script has the defer attribute
scripts[].inlinebooleanWhether the script is inline (has no src)
{"scripts":[{"src":"https://example.com/app.js","type":"module","async":false,"defer":false,"inline":false},{"src":"","type":"text/javascript","async":false,"defer":false,"inline":true}]}

Errors

ConditionExit codeStderr
Chrome not connected2error: connecting to Chrome: ...
Timeout3error: timeout

Examples

List all scripts:

hubcap scripts

Count the number of external scripts:

hubcap scripts | jq '[.scripts[] | select(.src != "")] | length'

Detect third-party scripts by filtering out same-origin sources:

ORIGIN=$(hubcap url | jq -r '.url' | sed 's|^\(https\?://[^/]*\).*|\1|')
hubcap scripts | jq --arg o "$ORIGIN" '[.scripts[] | select(.src != "" and (.src | startswith($o) | not))]'

See also

  • links - extract all links from the page
  • images - list all images on the page
  • coverage - get JavaScript code coverage