Loading...
Loading...
WebKit integration in SwiftUI using WebView and WebPage for embedding web content, navigation, JavaScript interop, and customization. Use when embedding web content in SwiftUI apps.
npx skill4agent add rshankras/claude-code-apple-skills webkit-integrationWebViewWebPageWhat do you need?
|
+-- Display a URL or HTML content
| +-- Simple, no interaction needed
| | +-- WebView(url:) --> see webview-basics.md
| +-- Need loading state, reload, custom config
| +-- WebPage + WebView(page) --> see webview-basics.md
|
+-- Navigate programmatically (back, forward, intercept)
| +-- Back/forward list, navigation events
| | +-- see navigation.md
| +-- Intercept or cancel navigation requests
| +-- NavigationDeciding protocol --> see navigation.md
|
+-- Execute JavaScript or communicate with web content
| +-- callJavaScript, arguments, content worlds
| +-- see javascript-advanced.md
|
+-- Capture snapshots, export PDF, web archive
| +-- page.snapshot(), page.pdf(), page.webArchiveData()
| +-- see javascript-advanced.md
|
+-- Handle custom URL schemes
+-- URLSchemeHandler protocol --> see javascript-advanced.md| API | Minimum OS | Import |
|---|---|---|
| iOS 26 / macOS 26 | |
| iOS 26 / macOS 26 | |
| iOS 26 / macOS 26 | |
| iOS 26 / macOS 26 | |
| iOS 14 / macOS 11 | |
| iOS 11 / macOS 10.13 | |
| iOS 14 / macOS 11 | |
import SwiftUI
import WebKit
struct BrowserView: View {
var body: some View {
WebView(url: URL(string: "https://developer.apple.com")!)
}
}import SwiftUI
import WebKit
struct ControlledBrowserView: View {
@State private var page = WebPage()
var body: some View {
WebView(page)
.onAppear {
page.load(URLRequest(url: URL(string: "https://developer.apple.com")!))
}
}
}| Mistake | Problem | Fix |
|---|---|---|
Using | No access to back/forward, reload, or events | Use |
Forgetting | | Always import both |
Not observing | Missing loading states, errors go unnoticed | Use |
Calling | Script fails because DOM is not ready | Wait for |
| Using persistent data store for private browsing | User data is saved to disk | Use |
Not handling | Navigation proceeds when it should be cancelled | Return |
| Passing JavaScript without argument binding | Vulnerable to injection, hard to debug | Use |
WebPageSwiftUIWebKit.nonPersistent()arguments:findNavigator(isPresented:)| File | Contents |
|---|---|
| WebView creation, WebPage setup, configuration, find-in-page, customization modifiers |
| Loading content, back/forward list, navigation events, NavigationDeciding protocol |
| JavaScript execution, content worlds, snapshots, PDF export, custom URL schemes |
macos/architecture-patterns/ios/navigation-patterns/design/liquid-glass/