MCPcopy Create free account
hub / github.com/ScaleML/AgentSPEX / _save_current_page_html

Function _save_current_page_html

src/sandbox_vm/tools/web/utils.py:24–49  ·  view source on GitHub ↗

After navigating, capture HTML from the current page and save it into the session's url_download directory. Returns { handle }.

(ctx: Context, url: str)

Source from the content-addressed store, hash-verified

22
23
24async def _save_current_page_html(ctx: Context, url: str) -> Dict[str, Any]:
25 """
26 After navigating, capture HTML from the current page and save it into the
27 session's url_download directory. Returns { handle }.
28 """
29 rt = MANAGER.get(_sid(ctx))
30
31 # Fetch HTML from current page (no disk IO from the browser tool)
32 html_res = await _browser_page_html(ctx)
33 if "error" in html_res:
34 return html_res
35
36 html = html_res.get("html", "")
37 out_dir = rt.root / "url_download"
38 out_dir.mkdir(parents=True, exist_ok=True)
39 fname = _url_to_filename(url)
40 path = out_dir / fname
41
42 try:
43 path.write_text(html, encoding="utf-8")
44 except Exception as e:
45 return _err("WRITE_ERROR", message=str(e))
46
47 handle = rt.publish_path(path, perm="r", label=f"page-{fname}")
48 rt.touch()
49 return _ok(handle=handle)
50
51
52async def web_fetch_urls(ctx: Context, urls: List[str]) -> dict:

Callers 1

web_fetch_urlsFunction · 0.85

Calls 8

_sidFunction · 0.90
_browser_page_htmlFunction · 0.90
_errFunction · 0.90
_okFunction · 0.90
_url_to_filenameFunction · 0.85
getMethod · 0.80
publish_pathMethod · 0.80
touchMethod · 0.45

Tested by

no test coverage detected