After navigating, capture HTML from the current page and save it into the session's url_download directory. Returns { handle }.
(ctx: Context, url: str)
| 22 | |
| 23 | |
| 24 | async 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 | |
| 52 | async def web_fetch_urls(ctx: Context, urls: List[str]) -> dict: |
no test coverage detected