Skip to content

markbattistella/BrowserKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.


Important Notice: WebView Renamed to BrowserView (iOS 26 Compatibility)

With iOS 26, Apple introduced a native type named WebView, which conflicts with BrowserKit's WebView. To avoid namespace collisions:

  • The WebView type has been renamed to BrowserView
  • WebView is now deprecated and will be removed in iOS 26+
  • You should update all usage of WebViewBrowserView

Migration Example

// Deprecated
WebView(url: URL(string: "https://example.com")!)

// ✅ Update to:
BrowserView(url: URL(string: "https://example.com")!)

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 {
        BrowserView(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 {
        BrowserView(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 {
        BrowserView(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:

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

WebKit Configuration

You can also customise the WKWebViewConfiguration or the WKWebView itself:

BrowserView(
    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.

About

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

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors

Languages