Skip to content
Why is my JavaScript content blank?

Why is my JavaScript content blank?

Because the capture happens as soon as the DOM has loaded, and your script had not drawn anything yet. The layout, headings and static content all come through, and the chart is an empty rectangle. Nothing errors.

Tell the conversion what to wait for:

doc.WaitVisible(".highcharts-root", selector.ByQueryAll)

Pick a selector that only exists once the drawing is finished. Charting libraries usually append an <svg> or a container element when they complete, which is exactly the signal you want.

Which wait to use

CallWaits for
WaitVisible(sel, by)The element exists and is visible. The usual choice.
WaitReady(sel, by)The element exists in the DOM, visible or not.
WaitTime(d)A fixed duration, whether or not anything happened.

Prefer a selector over a duration. WaitTime costs its full value on every conversion even when the page was ready immediately, and still guesses wrong when the network is slow.

WaitTime earns its place when nothing observable appears: content drawn into a <canvas> that already existed, for instance, changes no element you can select.

Register more than one selector if you need to. All of them have to be satisfied.

Matching modes

The second argument controls how the selector is read, and defaults to selector.BySearch:

ModeEquivalent to
selector.BySearchDOM.performSearch, takes CSS or XPath
selector.ByQuerydocument.querySelector()
selector.ByQueryAlldocument.querySelectorAll()
selector.ByIDdocument.querySelector('#' + id)

Use ByQueryAll when the page has several charts, so the wait covers all of them rather than the first.

When the wait does not help

A selector that never appears does not fail quickly. The conversion runs to the timeout and then returns that, so a misspelled class name costs the full 15 seconds and looks like a slow server. Check the selector in a browser console first.

If the script comes from a CDN, the container is what fetches it. Without outbound network access the library never loads, the selector never appears, and you get a timeout that looks nothing like a network problem. Bundle the library into the asset directory if the container has no internet access.

A page that legitimately needs longer than 15 seconds needs the budget raised as well as the wait set:

doc.SetTimeoutDuration(60 * time.Second)

WaitTime is capped at three minutes and rejected above that with too long minimum load time. Maximum is 3 minutes. The server caps a whole query at ten minutes.

Wait for rendering covers this with the Highcharts example, which is blank without its WaitVisible line and correct with it.

Last updated on