hubcap layout — Get element layout with child positions

When to use

Get element layout with child element positions. Use bounds for just the element’s bounding box. Increase --depth for deeper nesting.

Usage

hubcap layout <selector> [flags]

Arguments

ArgumentTypeRequiredDescription
selectorstringyesCSS selector of the element

Flags

FlagTypeDefaultDescription
—depthint1Depth of children to include

Output

FieldTypeDescription
tagNamestringThe element’s tag name
boundsobjectThe element’s bounding box (x, y, width, height)
childrenarrayChild elements with their own layout info
{
  "tagName": "DIV",
  "bounds": {"x": 0, "y": 0, "width": 800, "height": 600},
  "children": [
    {
      "tagName": "HEADER",
      "bounds": {"x": 0, "y": 0, "width": 800, "height": 60}
    }
  ]
}

Errors

ConditionExit codeStderr
Element not found1error: element not found: <sel>
Chrome not connected2error: connecting to Chrome: ...
Timeout3error: timeout

Examples

Get the layout of a container:

hubcap layout '#app'

Get a deeper layout tree and extract child widths:

hubcap layout '#app' --depth 3 | jq '.children[] | {tag: .tagName, width: .bounds.width}'

See also

  • bounds - Get just the element’s bounding box
  • styles - Get computed CSS styles
  • domsnapshot - Get a full DOM snapshot