MCPcopy Create free account
hub / github.com/diillson/chatcli / navigateAndSerialize

Function navigateAndSerialize

cli/plugins/webfetch_render.go:343–362  ·  view source on GitHub ↗

navigateAndSerialize drives the actual navigation and returns the settled DOM, capped at maxRenderedHTMLBytes.

(page *rod.Page, target string)

Source from the content-addressed store, hash-verified

341// navigateAndSerialize drives the actual navigation and returns the
342// settled DOM, capped at maxRenderedHTMLBytes.
343func navigateAndSerialize(page *rod.Page, target string) (string, error) {
344 if err := page.Navigate(target); err != nil {
345 return "", fmt.Errorf("navigating: %w", err)
346 }
347 if err := page.WaitLoad(); err != nil {
348 return "", fmt.Errorf("waiting for page load: %w", err)
349 }
350 // Late XHR fills: best-effort settle; on slow pages the deadline wins
351 // and we serialize whatever has rendered so far.
352 _ = page.WaitDOMStable(domStableWindow, domStableDiff)
353
354 html, err := page.HTML()
355 if err != nil {
356 return "", fmt.Errorf("serializing rendered DOM: %w", err)
357 }
358 if len(html) > maxRenderedHTMLBytes {
359 html = html[:maxRenderedHTMLBytes]
360 }
361 return html, nil
362}
363
364// hijackPageRequests installs the in-browser SSRF layer: every network
365// request the rendered page issues is validated before it leaves Chromium,

Callers 1

renderPageHTMLFunction · 0.85

Calls 1

ErrorfMethod · 0.80

Tested by

no test coverage detected