Loading...
Loading...
Save a live webpage as a high-fidelity PDF that preserves the original layout AND every image (including lazy-loaded ones) using the agent-browser CLI. Use this whenever the user asks to "download this page as PDF", "save this article", "archive this URL", "fetch this page for reference", or otherwise wants a local PDF of a web page that looks like the browser version. Especially important on modern JS-heavy sites (engineering blogs, Next.js sites, anything with IntersectionObserver lazy loading) where naive `chrome --headless --print-to-pdf` or a bare `agent-browser pdf` produces blank rectangles or broken-image placeholders. Trigger this skill even when the user does not name the tool - any request to capture a webpage's full visual content as a PDF on disk should pull this in. For reader-mode/article-only output (no nav, no footer, no manual trimming) prefer percollate instead - see "When NOT to use this".
npx skill4agent add tenequm/skills download-webpage-as-pdfchrome --headless --print-to-pdfagent-browser pdfopenawait<img>evalpdfagent-browser --session <unique-name> ...AGENT_BROWSER_HEADED=false~/.agent-browser/config.json"headed": true--headed false--headedexport AGENT_BROWSER_HEADED=false
agent-browser open <URL>
agent-browser wait --load networkidle
agent-browser eval "(async () => {
const sleep = ms => new Promise(r => setTimeout(r, ms));
['#onetrust-banner-sdk','#onetrust-consent-sdk','.ot-sdk-container','#ot-sdk-btn-floating','[id*=cookie]','[id*=consent]','[id*=onetrust]'].forEach(s => document.querySelectorAll(s).forEach(e => e.remove()));
document.querySelectorAll('img').forEach(img => {
img.removeAttribute('loading');
img.removeAttribute('decoding');
if (img.dataset.src) img.src = img.dataset.src;
if (img.dataset.srcset) img.srcset = img.dataset.srcset;
});
for (let y = 0; y < document.documentElement.scrollHeight + 2000; y += 400) {
window.scrollTo(0, y);
await sleep(200);
}
window.scrollTo(0, document.documentElement.scrollHeight);
await sleep(2000);
await Promise.all(Array.from(document.images).map(i =>
i.complete && i.naturalWidth ? null
: new Promise(r => { i.addEventListener('load', r, {once:true}); i.addEventListener('error', r, {once:true}); setTimeout(r, 5000); })
));
window.scrollTo(0, 0);
await sleep(500);
return Array.from(document.images).filter(i => !i.naturalWidth).length;
})()"
agent-browser pdf /tmp/page.pdf
agent-browser close
# Verify the result
pdfinfo /tmp/page.pdf | grep -E "Pages|File size"eval0pdfinfowait --load networkidleloadingloading=lazyawait Promise.all<img>evalpdf# 1. Inspect total page count and visually identify which trailing pages are footer
pdfinfo /tmp/page.pdf | grep Pages
# Use the Read tool on the PDF to see the last few pages and decide where the article ends.
# 2. Trim footer pages. The "1-9" below is illustrative ONLY - replace with the
# article's actual range from pdfinfo + visual inspection. Do not copy this verbatim.
qpdf /tmp/page.pdf --pages . 1-9 -- /tmp/page-trimmed.pdf
# 3. Compress (typically 60-70% reduction with images intact)
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook \
-dNOPAUSE -dQUIET -dBATCH \
-sOutputFile=/path/to/final.pdf /tmp/page-trimmed.pdf-dPDFSETTINGS=/ebook/screennpx percollate pdf <URL> -o out.pdf--no-hyphenate --css "@page { size: A4; margin: 18mm; } a[href]::after { content: none !important; }"agent-browser screenshot --full-pagemonolithsingle-file CLI