BrowserKit

2.0.1

BrowserKit is a Swift package that provides a simple and flexible way to integrate web views into your iOS, macOS, and visionOS applications.
markbattistella/BrowserKit

What's New

2.0.1

2024-11-25T00:25:24Z

Full Changelog: 1.0.0...2.0.1

BrowserKit

Swift Version

OS Platforms

Licence

BrowserKit is a Swift package that provides a simple and flexible way to integrate web views into your iOS, macOS, and visionOS applications. It supports both SFSafariViewController for seamless web browsing on iOS and WKWebView for custom web content handling across platforms.

Features

  • Cross-Platform Support: Works with iOS, macOS, visionOS, and Catalyst.
  • Safari and WebKit Integration: Choose between SFSafariViewController for a native browsing experience or WKWebView for custom web content.
  • Customisable Configurations: Easily configure both Safari and WebKit views with flexible closures.
  • HTML String Loading: Load HTML content directly into a WKWebView with optional base URLs.

Installation

Swift Package Manager

To add BrowserKit to your project, use the Swift Package Manager.

  1. Open your project in Xcode.

  2. Go to File > Add Packages.

  3. In the search bar, enter the URL of the BrowserKit repository:

    https://github.com/markbattistella/BrowserKit
  4. Click Add Package.

Usage

Basic Example

Loading a URL with Safari

You can load a URL using SFSafariViewController on iOS, visionOS, and Catalyst platforms:

import BrowserKit

struct ContentView: View {
    var body: some View {
        WebView(url: URL(string: "https://markbattistella.com")!)
    }
}

Loading a URL with WebKit

For custom web content handling, you can use WKWebView on any platform:

import BrowserKit

struct ContentView: View {
    var body: some View {
        WebView(url: URL(string: "https://markbattistella.com")!, webKitConfiguration: { config in
            config.preferences.javaScriptEnabled = true
        }, webViewConfiguration: { webView in
            webView.navigationDelegate = self // Set your custom navigation delegate
        })
    }
}

Loading HTML Content

You can also load raw HTML content into a WKWebView:

import BrowserKit

struct ContentView: View {
    var body: some View {
        WebView(htmlString: "<html><body><h1>Hello, World!</h1></body></html>")
    }
}

Customisation

Safari Configuration

You can customise the Safari view controller's configuration with the safariConfiguration closure:

WebView(url: URL(string: "https://markbattistella.com")!) { sfConfiguration in
    sfConfiguration.entersReaderIfAvailable = true
}

WebKit Configuration

You can also customise the WKWebViewConfiguration or the WKWebView itself:

WebView(
    url: URL(string: "https://markbattistella.com")!,
    webKitConfiguration: { wkConfig in
        wkConfig.allowsInlineMediaPlayback = true
    },
    webViewConfiguration: { webView in
        webView.customUserAgent = "MyCustomUserAgent"
    }
)

Contributing

Contributions are welcome! If you have suggestions or improvements, please fork the repository and submit a pull request.

License

BrowserKit is released under the MIT license. See LICENSE for details.

Description

  • Swift Tools 5.10.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri May 16 2025 09:53:27 GMT-0900 (Hawaii-Aleutian Daylight Time)