Get the latest tech news

Creating a Safari webarchive from the command line


We can use the `createWebArchiveData` method on `WKWebView` to write a Swift script that creates Safari webarchive files.

I already have tools to take screenshots, and I love them as a way to take quick snapshots and skim the history of a site, but bitmap images aren’t a great archival representation of a website. If there’s some error getting the page – say, my Internet connection is down or the remote server doesn’t respond – the WKWebView will still complete loading and set isLoading = false. I saw a lot of different failures when archiving such a wide variety of URLs, including esoteric HTTP status codes, expired TLS certificates, and a couple of redirect loops.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Safari

Safari

Photo of command line

command line

Photo of Safari webarchive

Safari webarchive

Related news:

News photo

WebKit Features in Safari 17.5

News photo

Breaking the news: publishers beg Apple not to block ads in Safari

News photo

Data Science at the Command Line, 2nd Edition (2021)