# Debugging Janus SDK

This document outlines how to use the debugging features available in the Janus SDK.

## Building in Debug Mode

To build the Janus SDK in debug mode, use the `--debug` flag with the build script:

```bash
./iOS/build_xcframework.sh --debug
```

This will build the framework with the `Debug` configuration instead of `Release`. The Debug configuration sets the preprocessor definition `DEBUG=1`, which enables:

1. Additional logging throughout the codebase
2. WebView debugging capabilities
3. Safari Web Inspector integration (iOS 16.4+)

## WebView Debugging

When built in debug mode, all WebViews created through the SDK automatically include:

1. Safari Web Inspector support (for iOS 16.4+)
2. JavaScript event monitoring
3. Console logging capture

### Using Safari Web Inspector

To debug WebViews in Safari:

1. On your development Mac, open Safari
2. Enable the Develop menu: Safari > Preferences > Advanced > "Show Develop menu in menu bar"
3. Connect your iOS device or launch your app in the Simulator
4. In Safari, go to Develop > [Your Device/Simulator] > [Your WebView]
5. You'll see the Safari Web Inspector with access to:
   - Console logs
   - Network requests
   - DOM inspection
   - JavaScript debugging

### Debug API

In debug builds, the SDK exposes additional debugging methods through `WebViewManager.Debugging`:

```swift
// Run Fides debug check to test for Fides integration
if #available(iOS 14.0, *) {
    WebViewManager.Debugging.runFidesDebugCheck(in: webView)
}

// Show Fides modal programmatically
if #available(iOS 14.0, *) {
    WebViewManager.Debugging.showFidesModal(in: webView)
}
```

These methods are only available in debug builds and will not be included in release builds.

## Debug Output

When in debug mode, the SDK logs additional information with a 🐞 emoji prefix. Look for these log messages in your Xcode console to track WebView and Fides integration behavior.

Example debug log messages:

```
🐞 JanusSDK: Debug helper initialized
🐞 JanusSDK: WebView registered for debugging
🐞 JanusSDK: Debug mode enabled for WebView
🐞 FIDES EVENT: FidesInitialized
```

## Troubleshooting Common Issues

### WebView Not Loading Content

If your WebView isn't loading content correctly:

1. Check your console for JavaScript errors
2. Verify network requests are completing successfully
3. Examine the DOM to ensure Fides script tags are present

### Consent Values Not Synchronizing

If consent values aren't synchronizing between WebViews:

1. Use `runFidesDebugCheck(in:)` to verify Fides is initialized
2. Check console logs for any Fides event failures
3. Verify that the `window.Fides.consent` object contains the expected values

### Modal Not Appearing

If the privacy modal isn't appearing:

1. Use `showFidesModal(in:)` to manually trigger the modal
2. Check if any JavaScript errors are occurring
3. Verify the component is properly registered in the Fides configuration 