GithubHelp home page GithubHelp logo

doc22940 / webarchiver Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ernesto-elsaesser/webarchiver

0.0 1.0 0.0 9 KB

A Swift package that saves web pages as WKWebView-compatible offline archives.

License: MIT License

Swift 100.00%

webarchiver's Introduction

WebArchiver

A Swift package that compresses full web pages into single archive files that can later be loaded into a WKWebView. It may be used to implement offline reading features.

The main method WebArchiver.achive(...) takes a URL and optionally a list of cookies. The archiver will download the main HTML document and all linked HTML, CSS, JavaScript (optionally) and image resources. All resources are then packed into a single .webarchive file. The archiver parallelizes HTTP requests, but works on a single serial queue to process the responses.

A sample project that demostrates how to combine the WebArchiver with WKWebView can be found here: OfflineWebView

Installation

This repository is a Swift Package Manager package. Use Xcode to add it as a dependency. Or simply copy and paste the 3 source files into your project and add Fuzi as a dependency via your package manager of choice.

Motivation

This package was created because WKWebView (in contrast to the deprecated UIWebView) does not offer a universal way to make arbritary web content available offline. WebKit's own HTTP caching unfortunately does provide enough control for most use cases, and a lot of stuff happens "out-of-process" (see here or here).

But WKWebView can import .webarchive files, which are binary PLIST files following a defined (undocumented) format. Being able to create .webarchive therefore allows apps to save online content to offline reading. Such files can be loaded into the WKWebView via loadFileURL(URL:allowingReadAccessTo:) where URL is a file://... URL.

Limitations

The archiver will only work well with static content. As soon as a web page needs to dynamically load resources via JavaScript, there is no sane way to archive that page into a single file without virtually replicating the backend. The archiver also doesn't scan JavaScript for statically linked resources. It does scan CSS files for image URLs though.

The archiver is further limited to the common resource types of web pages, i.e. HTML, CSS, JavaScript and images. If a web page has statically linked resources of other types (i.e. audio, video, ...) these resources won't be included in the archive. If you need to support such pages, I recommend to fork the repo and extend the archiver to include the required types.

Dependencies

The package uses Fuzi as HTML parser.

webarchiver's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.