microsim-iframe-tester
MicroSim Iframe Height Tester
Purpose
MicroSims are embedded in MkDocs pages via <iframe> tags with fixed heights and scrolling="no". If the iframe height is too short, controls at the bottom (sliders, buttons, dropdowns) get clipped and students can't interact with them. This skill automates checking that every MicroSim's controls are fully visible at the declared iframe height.
How It Works
Always use the Python script (scripts/test-iframe-heights.py) — it only requires pip install playwright and avoids any Node.js/npm dependency. A legacy Node.js version (scripts/test-iframe-heights.js) exists but should not be used. The script uses Playwright to:
- Find all MicroSim directories under
docs/sims/ - Read each
index.mdto extract the declared iframe height - Load
main.htmlin a browser viewport constrained to that height - Wait for p5.js (or other libraries) to finish rendering controls
- Find all interactive elements (buttons, sliders, selects, inputs, checkboxes)
- Check whether each element's bounding box fits within the iframe height
- Measure the actual content height needed
- Report pass/fail with recommended height for failures
Prerequisites
pip install playwright
playwright install chromium
Running the Tests
# Test all MicroSims
python scripts/test-iframe-heights.py --sims-dir docs/sims
# Test a single MicroSim
python scripts/test-iframe-heights.py --sims-dir docs/sims --sim energy-pyramid
# Test with a custom height override (ignores index.md heights)
python scripts/test-iframe-heights.py --sims-dir docs/sims --height 530
# Generate a markdown report
python scripts/test-iframe-heights.py --sims-dir docs/sims --report report.md
Reading the Output
The script outputs a table like:
MicroSim | Iframe Height | Content Height | Status | Suggested Height
----------------------------|---------------|----------------|--------|------------------
energy-pyramid | 532 | 528 | PASS | 532
predator-prey | 697 | 720 | FAIL | 730
greenhouse-effect | 500 | 498 | PASS | 500
- PASS: All controls fit within the iframe height (with 5px tolerance)
- FAIL: One or more controls extend below the iframe boundary
- Suggested Height: The actual content height rounded up to the nearest 10px, plus a 10px safety margin. If the sim's JS file contains a
// CANVAS_HEIGHT = Ncomment, that declared height is used instead of the measured content height (responsive sims can measure taller at the test viewport width than they actually render in MkDocs).
Responsive Sims and CANVAS_HEIGHT
Some p5.js sims dynamically resize their canvas based on viewport width. The test viewport (700px) may not exactly match the MkDocs content column, causing measured heights to differ from the actual embedded height. When a sim declares // CANVAS_HEIGHT = N in its JS file, the tester trusts that value as authoritative. Always sanity-check suggestions for responsive sims — if the suggested height is dramatically larger than the current iframe height, the sim likely has dynamic sizing and needs a CANVAS_HEIGHT declaration rather than a blind height increase.
Fixing Failures
For each failing MicroSim, update the iframe height in index.md:
<!-- Before -->
<iframe src="main.html" height="500" width="100%" scrolling="no"></iframe>
<!-- After — use the suggested height from the report -->
<iframe src="main.html" height="540" width="100%" scrolling="no"></iframe>
Also update the // CANVAS_HEIGHT: comment in the JavaScript file if present, and any chapter markdown files that embed the same sim.
Step-by-Step for Claude
When the user asks to test iframe heights:
- Confirm the project root contains
docs/sims/with MicroSim directories - Check that
scripts/test-iframe-heights.pyexists in the skill directory at~/.claude/skills/microsim-iframe-tester/scripts/ - Run
playwright install chromiumif not already installed - Run the Python test script from the project root
- Present the results to the user
- For failures, offer to update the iframe heights in the affected
index.mdfiles - If chapter markdown files also embed the failing sims, update those too