Description
scripts/testing/capture-page.csx evaluates a page script, prints its return value, and then inspects that value for width/height so a document can crop the capture to an element by returning its getBoundingClientRect().
That inspection indexes the value as a JSON object. When the script returns a number, string, boolean or array, it throws InvalidOperationException: The node must be of type 'JsonObject' — after the value has already been printed correctly. The caller gets the right answer on stdout, a non-zero exit, and a stack trace naming System.Text.Json rather than the snippet.
Reproduction steps
'return document.querySelectorAll("div").length' |
dotnet script scripts/testing/capture-page.csx -- --url "http://localhost:PORT/" --out out.png --script-stdin
Measured 2026-09-29 during #348's verification pass.
Actual behaviour
The count prints, then:
System.InvalidOperationException: The node must be of type 'JsonObject'.
at System.Text.Json.Nodes.JsonNode.AsObject()
at Submission#0...capture-page.csx:line 224
Expected behaviour
A non-object return is a normal thing for a snippet to do. The crop is optional, so its absence should simply mean "no crop": skip the inspection unless the value is an object carrying width and height, keep the printed value, and exit 0. If a shape genuinely cannot be used, say so in terms of the snippet rather than of JSON node types.
Why it matters beyond one mistake
Several documents state their reads as browser-console js blocks returning arrays — notifications-and-changelog/13 steps 3, 6 and 7, notifications-and-changelog/14 step 2. Any of those piped through the harness fails this way, and the failure looks like the page rather than the tooling.
Definition of done
Description
scripts/testing/capture-page.csxevaluates a page script, prints its return value, and then inspects that value forwidth/heightso a document can crop the capture to an element by returning itsgetBoundingClientRect().That inspection indexes the value as a JSON object. When the script returns a number, string, boolean or array, it throws
InvalidOperationException: The node must be of type 'JsonObject'— after the value has already been printed correctly. The caller gets the right answer on stdout, a non-zero exit, and a stack trace namingSystem.Text.Jsonrather than the snippet.Reproduction steps
Measured 2026-09-29 during #348's verification pass.
Actual behaviour
The count prints, then:
Expected behaviour
A non-object return is a normal thing for a snippet to do. The crop is optional, so its absence should simply mean "no crop": skip the inspection unless the value is an object carrying
widthandheight, keep the printed value, and exit0. If a shape genuinely cannot be used, say so in terms of the snippet rather than of JSON node types.Why it matters beyond one mistake
Several documents state their reads as browser-console
jsblocks returning arrays —notifications-and-changelog/13steps 3, 6 and 7,notifications-and-changelog/14step 2. Any of those piped through the harness fails this way, and the failure looks like the page rather than the tooling.Definition of done