Show HN: Kage – Shadow any website to a single binary for offline viewing

1 day ago (github.com)

I was intrigued to see how the demo GIF in the README was generated: https://github.com/tamnd/kage/blob/01e75b87ecc893bbba7943c63...

Turns out it's using another project by the same author: https://github.com/tamnd/ascii-gif

The script used for the demo is at https://github.com/tamnd/kage/blob/01e75b87ecc893bbba7943c63... and has a comment showing how to run it:

  ascii-gif render docs/demo/kage.tape -o docs/static/demo.gif

Looks like it's an opinionated wrapper around https://github.com/charmbracelet/vhs

One use I'd have for this is company wikis that you want to give folks easy offline access to (maybe the wiki has documentation that's useful at sites that don't have cellular coverage).

Cool!

It would be especially cool to have a version that didn't require the separate serving process - even though it's nifty you can package up a whole site as a single binary.

Maybe a single HTML entrypoint shim with a bit of javascript that could index into an archive (potentially embedded) of the site's content?

  • Submitting this to Hacker News is the right place! Thanks for your idea. I will consider implementing that :)

    Also, in my mind, I already have a script/program to convert HTML to Markdown, so it could actually store everything on disk as a folder of Markdown files, and then commit them to a Git repo.

    • I'd like to request something between what GP suggested and what your program is doing currently - basically I still want a single binary, but instead of embedding a full browser in it, I would like the binary to be just a self-extracting archive that calls the user's default browser, maybe in a new window/frame.

      Basically I'm looking for something like the old-school .chm files on Windows, where you could pack a bunch of HTML documents into a single archive and open it without needing to embed a full browser engine.

      This would have the advantage of keeping the file sizes really small. And you don't have to worry about the browser engine become outdated and potentially becoming an attack vector.

      2 replies →

    • I think the zim flow was perfect for offline use. I know I will be making use of it as soon as I can figure out how to pass chrome the cookies so I can be signed into the site. Didn't see it in the page, but I didn't look closely yet.

      1 reply →

    • Not to load you up with too many ideas, but a markdown folder sounds a lot like obsidian, which has a plugin system now.

      Epub would also be a great target.

    • I would use the shit out of this. I'm a heavy user of Logseq (OG, the md file-based version). Would LOVE to save my favorite web resources this way.

  • This is a nice way to do it if you’re already stuck with a solution (print to PDF would probably also, if you can script it).

    In a green field world, I have a personal requirement that technical documentation systems are capable of bulk exporting to a human-readable format on disk. I’m pretty flexible on what that is, though. Markdown is preferred, but I’m also fine with static, dependency-free HTML and I could accept PDFs if the rest of it is super nice.

    It’s an integral part of DR, and most places want their docs on-premise, so DR effectively requires offline documentation. Everywhere I’ve worked either a) writes documentation in something that works offline (eg git repo with tarballs somewhere), or b) has invested a bunch of time in trying to scrape their own wiki into something legible during DR.

    I guess it’s a long-winded way of saying “that’s using a tool to fix a self-inflicted problem that shouldn’t exist”.

> No tracking, no network calls, no surprises.

Won't comment on a project (though idea seems interesting) but this in README is a tell for me ;)

> kage serve $HOME/data/kage/paulgraham.com

If the result is static why does it need a server? Isn't it possible to make it so that it can simply be opened by the browser? Like:

$ firefox $HOME/data/kage/paulgraham.com

Then the result would be useable on machines without kage nstalled.

  • You could use python -m http.server instead. I haven't tried it yet, but it should work.

    Actually, Kage has two parts: a crawler that crawls pages and converts them to clean HTML by capturing the DOM after rendering in Chrome/Chromium, and a pack/serve component that packages the result as either a ZIM file for Kiwix or an executable file.

  • Usually JavaScript is blocked when you load pages that way.

  • You’ll likely run into a ton of CORS issues doing that.

    • I don't think so, there is no HTTP requests being done from JS as it's stripped away, and all the other resources are pulled down (and I'm assume their reference made relative), so really shouldn't be any issues because of CORS at all.

I find SingleFile [0] to be a much more robust version of this.

It strips out all the JavaScript too, but also packs everything into a single HTML file that is easy to transfer. Binary assets (like web fonts and images) are packed as base64 strings.

They also offer a CLI powered by Puppeteer. [1]

[0]: https://github.com/gildas-lormeau/singlefile

[1]: https://github.com/gildas-lormeau/single-file-cli

  • It seems this repo only saves one web page?

    What I'm implementing here is mirroring a whole website, with all its subpages, so you can browse it all offline. For example, all essays from paulgraham.com.

  • Love love love SingleFile too. The FF extension works pretty well for a clean save.

    That said, Kage looks promising if OP can combine SingleFile reproduction quality with the HTTPTrack spidering approach. SPA's are kinda tricky with archiving and do wonder how well Kage would handle that

    • I've seen the option in IE- .mhtml.

      For some reason it displays in IE better but I don't recall seeing this option in chrome of Firefox recently..

  • And thanks for the link. Let me implement this single HTML feature, it looks nice to have!

    • Yeah. An idea on top of that is to bundle an entire website into a single HTML page, with vendored JavaScript to enable client-side routing (all of the original pages' JS is still stripped out).

      That way, the page is self-contained as it is, but requires no bundled binary code to serve the site. It is actually safer security-wise.

      The vendored script can be as simple as this:

        const site = {
          "path-1": "<!DOCTYPE html><html> ... </html>",
          "path-2": "<!DOCTYPE html><html> ... </html>",
          // More paths
        }
      
        function attachListeners() {
          for (const [path, html] of Object.entries(site)) {
            document.querySelector(`a[href=${path}]`).onclick = () => {
              document.documentElement.outerHTML = html
              attachListeners()
            }
          }
        }
      
        document.addEventListeners("DOMContentLoaded", attachListeners)

  • What's the difference with, any webbrowser on a computer, File -> Save as ?

    • That's for a single page, this handles the whole site. Also the browser Save As options often work poorly.

    • Save As works fine for simple websites with static content.

      Let's say you have a site that fetches content from a database. If you Save As, then at best you'll get a local copy of an HTML page with JS that loads the content from the same remote database. It might not work (since the local copy has a different origin), or if it does, it requires you to be online, which defeats half of the purpose.

      What this project, and SingleFile, both do is save a snapshot of what the rendered page actually looks like at that moment in time. The scripts are stripped out so it runs locally and has no external dependencies.

  • This is what I first thought and it's a very elegant solution, and not needlessly overcomplicated.

I've been using httrack (https://www.httrack.com) to download wikis to read on flights, which isn't perfect but better than I'd found previously. I'll try this out, I'd be delighted to have good results. Thanks for the post.

This seems like it has potential to create a lot of load on a site- are there settings to set how fast it clones or avoid images/videos? Is there a way to only get a subset of a website?

  • Could you help create a new issue for that? I will do it later. It is already 1:00 AM my time, but I am happy that anyone is interested in it. : )

Neat project, I like the idea. One thing from a quick read: you launch Chrome with --no-sandbox. Is there a good reason for that? Security wise it's probably not a good idea. If there is no reason, I'd suggest leaving the sandbox on!

In any case, cool stuff :)

I've accumulated a bunch of old website archives over the years. The funny thing is the ugly HTML dumps have been more useful than the "perfect" archive.

It's one of the reasons I've become a bigger fan of RSS over time. A feed from 10-ish years ago is often more usable today than a carefully preserved (application) website.

  • Maybe it is just me, but by far most of the time, when I want to archive something from the internet, it is information and information is best served in an absolutely minimal text format like html or md.

  • I have a project for creating and archiving RSS feeds, keeping the full history from the time the crawler starts. I need to clean up a bit, then will open source it soon.

So this is like using wget --mirror except that it works on pages that require javascript, right?

  • Yeah, it is. For example, openai.com is rendered with Next.js, so I will try to mirror it tomorrow.

What is the best way to give coding agent a full website so that it can see what I see? With animation and design I’m never sure what it gets when I save the website in the browser. Maybe this is suitable?

This is cool. I could see myself downloading the articles behind the first couple pages of hacker news with this, for viewing on a flight or long distance train ride with spotty internet

I was floored by the idea of browsing docs offline but disappointed that recreating the demo of archiving Paul Graham’s essays gave me a ZIM with broken images and broken Unicode symbols when viewed in Kiwix.

Cool concept. I would like to see this combined with mitmproxy for archive grade fidelity. You could be saving exactly the data served and at the same time a representation by a modern (contemporary) browser, with all JS having run. This combination would be my perfect replacement for the WARC format.

  • I'm working on WARC too, with format from Common Crawl!

    By converting it to Markdown, we save a lot of space, but it is for a different purpose and a different project: https://github.com/tamnd/ccrawl-cli

    • That's neat! In my opinion, the WARC format is quite tricky and underspecified especially since HTTP2 introduced new semantics. It encodes too much in-band and requires rewriting of the server data. A mitmproxy capture is higher fidelity and supports capturing modern features such as WebSockets. I think if we could wrap Kage's crawler interactions by it and store its capture (the intercepted traffic), we could make a potentially nice new archival format.

      5 replies →

Suddenly remembering the days of dialup and your browser serving a fully-functional cached copy of a webpage when you try to access it and you're not online...

This is quite useful tool, especially for the cases where internet access is limited (the flights for example). I implemented it as a separate feature in mdview.io: for example you can export a document as a html file for offline usage, with all the presentation features like reach tables, mermaid and etc built in. Example https://mdview.io/s/why-markdown-became-default-format-for-a... then try to Export - Export HTML

This is interesting. Is the intended use case mostly read-only websites like blogs/docs/essays? How well does it handle sites where navigation, search, dropdowns, or other UI interactions depend on JavaScript?

  • Currently, all of that is broken. At one point, I had a traumatic experience where an archived HTML file kept redirecting to the live site, even though I already had all the content rendered, so I ended up disabling all JavaScript entirely.

Probably a stupid question, but could this archive embedded videos as well?

  • Possible, but currently I disable all large files, including videos.

    For video downloading, I suggest wrapping around yt-dlp. It's an awesome tool.

For those with an eReader, one thing that works really well is using pandoc to download and convert a webpage to EPUB that you can then load to your reader.

  pandoc --from html --to epub --output /PATH/TO/FILE.epub https://example.com

I tried to clone a HTTP (not HTTPS) site, and it's giving me `navigation failed: net::ERR_NAME_NOT_RESOLVED`. Even when I explicitly included the protocol with `http://<FQDN>`.

the readme uses paulgraham.com as an example (which is text articles mostly) and I never use "Save As" for a web page (for the reasons the author states), I always just print as PDF and save the PDF file.

for an entire website though of many pages I can see this can be useful.

Curious about "keep it for a decade" claim. Can something possibly break down the road?

Does this work for the Apple Docs website? Really tricky to get those offline.

  • Good news for you: here is the command to clone Apple Docs:

    ```bash bin/kage clone https://developer.apple.com/documentation/ \ --scope-prefix /documentation/ \ --out /Users/apple/data/apple-docs \ --chrome "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" \ --max-pages 0 --max-depth 0 \ --workers 3 --browser-pages 3 --asset-workers 6 \ --render-timeout 60s --settle 2s --timeout 30s \ 2>&1 | tee -a /Users/apple/apple-docs.log ```

    Adjust it to your needs :)

    I smoke-tested it, and all the content and CSS work, but I stripped all the JS, so the sidebar won't work.

    If you run into any problems, feel free to create new issues in the repo. It helps me prioritize and know what should be fixed.

  • Making docs available offline was one of my main motivations for building this tool. I will try Apple Docs too.

    I previously downloaded the Snowflake docs, and it was something like tens or even hundreds of thousands of pages, I do not remember exactly. The output ended up being very large.

    By the way, I forgot to add zstd compression support to my ZIM reader/writer. I will implement that in the next version.

Nice idea! fwiw, false positives and all, but the Windows 11 default Windows Security doesn't like it: `leakless.exe: Operation did not complete successfully because the file contains a virus or potentially unwanted software.`

The readme is AI slop, and incredibly grating to read. The disgust I felt while reading it almost put me off trying the project.

Is the code also AI slop?

Binary app is a really bad way of storing data. No one would ever want to run a binary shared with them or found online.

  • For sharing, better use the html folder or zim format, Kage supports both of them.

Cool project! I know it's written in go, but it would be cool to see something like this which uses Cosmopolitan Libc + redbean or something similar to create a binary which runs anywhere. Would be fun to be able to pass around self-executable website archives.

https://github.com/jart/cosmopolitan

https://justine.lol/cosmopolitan/index.html

https://redbean.dev

(Certificates just expired for justine's website, just ignore the warning.)

  • This could be a nice code golf project. It only needs a webview, a ZIM reader, and a way to append data to an existing binary and read it back.

    I did something like that a very long time ago (Of course, I have forgotten)

  • I never understood the appeal for cosmopolitan.

    I'd rather have platform specific minimal binaries than a single binary with hacks.

    Installing packages is a solved problem

    • Installing packages is a completely different activity than passing around self-executable archives among friends. Not everything needs to go through a CI pipeline and distribution platform before you can share it with others. On top of that, I really enjoy being able to write quick little utilities and then pass them around without worrying about what operating system anyone who stumbles upon it has.

      It's fine if you don't personally find it useful for your workflow, but I think it's mad cool, especially since you can zip together multiple binaries into one, along with data.

Amazing stuff!

I would recommend an add-on or new feature to detect and remove cookie banners / annoying popups that open on load (eg. sign up to my mailing list).

listing a few examples form fastText could help you.

You might also have the opposite problem though: some websites have content in the base html (so it's searchable by Google and they get views) and remove it on load (so you have to pay).

Capturing the initial html and comparing it to the final version could give you some hints and allow you to repair the removed content.

Best of luck with the project!

I've been using "Print to PDF" as my principle bookmarks management tool, since 1998, and I have over 90,000+ such PDF's sitting on my system, easily re-read and discovered.

So I don't quite get whats the point of kage? What does it do that print-to-PDF won't already do? The resulting .pdf's contain all the content, and also include the original URL and creation date, etc. How is kage an improvement?

How does it handle websites with client side paywalls? Can you run it with extensions like bypass paywalls and ublock origin?