A lightweight developer toolkit for inspecting WKWebView internals — built for SwiftUI. Explore localStorage, sessionStorage, cookies, and the live DOM tree, right inside your iOS app.
Heads up! WKDevKit is under active development. APIs, data models, and behaviors may change without notice as features stabilize.
We welcome issues, pull requests, and feedback — but please don’t rely on a stable public API just yet. Breaking changes are likely as the project evolves.
The embedded WebView includes a comprehensive Debug Panel accessible via the Debug button in the navigation bar. The panel provides three main tabs:
Real-time JavaScript console logging with:
- Captured Methods:
console.log,console.warn,console.error,console.info,console.debug - Visual Indicators:
- Color-coded messages (error=red, warn=orange, info=blue, debug=purple, log=default)
- Icons for each log type
- Timestamps for each message
- Features:
- Auto-scroll to latest log
- Clear button to remove all logs
- Selectable text for copying log messages
Interactive DOM tree visualization with multiple view modes:
- Hierarchical Display: Expandable/collapsible DOM nodes
- Element Information:
- Tag names with IDs and classes (e.g.,
div#header.nav-bar) - Inner text content preview (truncated to 50 chars)
- Child count indicators
- Tag names with IDs and classes (e.g.,
- Search Functionality:
- Filters nodes by tag, ID, class, or text content
- Highlights matching text in yellow
- Shows filtered vs total child count
- Requires 2+ characters to activate
- HTML Output: Properly formatted and indented HTML
- Text Content: Includes innerText from elements
- Search Functionality:
- Highlights all occurrences in yellow
- Case-insensitive matching
- Fully selectable text for copying
- Search FAB (top-right, orange): Toggle search input field
- Tree View FAB (bottom-right): Switch to hierarchical tree view
- Raw Text FAB (bottom-right): Switch to HTML text view
Comprehensive web storage inspection with automatic loading:
- Local Storage: Key-value pairs stored in localStorage
- Session Storage: Temporary session-based storage items
- Cookies: Document cookies with key-value parsing
- Features:
- Organized by storage type with section headers
- Item count display for each section
- Expandable long values (100+ characters)
- Auto-refresh when tab becomes visible
- Selectable text for copying
Displays current page information:
- Current URL with selectable text
- Clean, readable format
The WebView injects custom JavaScript to:
- Console Override: Intercepts console methods and forwards to native code
- DOM Extraction: Recursively traverses DOM tree to capture structure and content
- Storage Access: Extracts localStorage, sessionStorage, and document cookies
- WKWebView Configuration: Custom message handlers for JavaScript communication
- SwiftUI Integration: Modern declarative UI with proper state management
- Thread Safety: Uses
@MainActorfor safe WebView JavaScript evaluation
InAppWebViewInspector/
├── ContentView.swift # Main view with WebView type picker
├── EmbeddedWebView/
│ ├── WebView.swift # WKWebView wrapper with console/DOM/storage capabilities
│ ├── EmbeddedWebViewScreen.swift # Container screen
│ ├── DebugPanel.swift # Debug panel with navigation
│ ├── DebugTabView.swift # Tabbed debugging interface
│ ├── WebStorageView.swift # Web storage inspection
│ └── InfoView.swift # Page information display
├── Item.swift # SwiftData model
└── InAppWebViewInspectorApp.swift # App entry point
ConsoleMessage: Struct for console log dataWebStorageItem: Struct for storage data (localStorage, sessionStorage, cookies)WebStorageType: Enum for storage type classificationDOMNode: Decodable struct for DOM tree representationWebViewModel: Manages WebView reference and data fetchingConsoleMessageHandler: WKScriptMessageHandler for console logsWebView: UIViewRepresentable wrapper for WKWebView
DebugPanel: Main debug panel with navigation and state management
DebugTabView: Tabbed interface for debugging tools
WebStorageView: Storage inspection with sectioned displayWebStorageSection: Section headers for different storage typesWebStorageItemRow: Individual storage item display
InfoView: Current page information display
ConsoleView: Console log display with auto-scrollConsoleLogRow: Individual console message displayDOMInspectorView: DOM tree/raw view with search and FABsDOMNodeView: Recursive tree node display with search highlighting
- iOS 18.5+
- Xcode 15.0+
- Swift 5.0+
- Open
ExampleApp.xcodeprojin Xcode - Select your target device or simulator
- Build and run (Cmd+R)
The DOM Inspector provides both tree view and raw HTML modes with powerful search capabilities.
The Storage Inspector shows localStorage, sessionStorage, and cookies in organized sections.
- Launch the app
- Enter a URL in the text field
- Select "Embedded WebView" from the picker
- Tap "Launch" to open the WebView
- Tap "Debug" in the navigation bar to access debugging tools
- View all JavaScript console output in real-time
- Filter by log level using color coding
- Copy specific log messages for further analysis
- Explore the complete DOM structure
- Search for specific elements or content
- View element attributes and text content
- Export HTML structure via copy/paste
- Complete localStorage, sessionStorage, and cookie access
- Organized sectioned display by storage type
- Auto-loading when storage tab is accessed
- Expandable values for long content
- Global search across DOM tree
- Highlight matching elements
- Filter tree to show only relevant branches
- Case-insensitive text matching
See PROJECT_PLAN.md
This project is for educational and development purposes.


