This guide helps diagnose and resolve common issues when integrating GBGBridge.Documentation Index
Fetch the complete documentation index at: https://docs.go.gbgplc.com/llms.txt
Use this file to discover all available pages before exploring further.
Diagnostic Tools
BridgeHost exposes several built-in diagnostic surfaces — error state, a message log, and a list of pending requests — that should be your first stops when something looks off. Combined with Safari Web Inspector for the web side, these cover most debugging scenarios.
Observing lastError
The first thing to check isBridgeHost.lastError. It captures the most recent error from message decoding, JavaScript evaluation, or WebView attachment.
Message Log
BridgeHost.receivedMessages contains every successfully decoded message. Use it to verify message flow.
Pending Request Inspection
BridgeHost.pendingRequests shows requests awaiting a response. If this list grows unexpectedly, it means requests are arriving for actions with no registered handler.
Safari Web Inspector
For inspecting the web side of the bridge:- Enable Web Inspector on your device: Settings → Safari → Advanced → Web Inspector.
- Connect your device to a Mac.
- In Safari on Mac, go to Develop → [Your Device] → [Your App].
- Use the console to inspect
window.GBGBridgeand test message sending.
Common Issues
Most bridge problems fall into a small set of recurring categories — message routing, capability discovery, network/ATS, and SwiftUI state plumbing. Each entry below describes the symptoms, the likely causes, and the fix.Messages Not Being Received by the Host
Symptoms: The web journey sends messages, butreceivedMessages stays empty.
Possible causes
-
Wrong message handler name. The web journey must use exactly:
Note the lowercase
gingbgBridge. -
WebView not configured. Ensure you used
BridgeWebVieworBridgeWebViewConfigurator.configure(_:host:). A plainWKWebViewdoes not have the message handler registered. -
Bootstrap script not injected. If the web journey tries to send a message before the bootstrap script runs,
window.webkit.messageHandlers.gbgBridgemay not exist. The bootstrap script runs at document start, but if you’re configuring the WebView after navigation begins, messages may be lost.
Messages Not Being Received by the Web Journey
Symptoms:send(event:data:) or respond(to:...) is called, but the web journey doesn’t receive the message.
Possible causes
-
WebView not attached. Check
lastError— it will say"WebView not attached"if the WebView reference was lost. -
window.GBGBridge.receivenot defined. The web journey must replace the no-opreceive()with its own implementation. Check from Safari Web Inspector: -
JavaScript evaluation error. Check
lastErrorfor messages starting with"evaluateJavaScript failed:". -
Page navigated away. If the WebView navigated to a different page, the bridge context is lost. The bootstrap script re-runs on each page load, but the web journey must reinitialize its
receive()function.
window.GBGBridge.receive after page load and that the WebView is attached to the host.
Message Decoding Failures
Symptoms:lastError says "Failed to decode message: ...".
Possible causes
-
Malformed JSON. The web journey is sending a message that doesn’t match the
BridgeMessagestructure. -
Missing required fields. Every message must have:
version,correlationId,type,timestamp, andpayload(with at leastaction). -
Wrong type for
typefield. Must be one of:"request","response","event".
Capability Query Returns Unexpected Results
Symptoms: The web journey receives acapability.query response, but capabilities are missing or incorrect.
Possible causes
-
Typed slot without a handler. When using
init(hostVersion:), a slot only appears as supported ifhandleris set andisEnabledistrue. If you forgot to set a handler, the slot won’t appear. -
Slot is disabled. Check that
isEnabledhasn’t been set tofalseon the slot. -
Capabilities not declared (configuration-based init). When using
init(configuration:), only capabilities in theBridgeConfigurationdictionary are reported. -
Custom capability not registered. If using
registerCustomCapability(), ensure it was called before the query.
handler is set: host.documentCapture.isSupported should be true. For configuration-based init, review your BridgeConfiguration.
Permission State Not Appearing in Query Response
Symptoms: ThepermissionState field is missing from the capability query response.
Possible causes
-
Not using typed slots. Permission state is only included automatically when using
init(hostVersion:)with typed slots that havepermissionStateset. -
CameraDetector not called. The default
permissionStateis.notDetermined. CallCameraDetector.check()and assign the result. -
Using configuration-based init without permissionState. The
BridgeCapabilityInfopermissionStatefield defaults tonil. Set it explicitly.
Handler Not Called for Requests
Symptoms: A request arrives (visible inreceivedMessages) but the handler’s handle() method is never called. The request appears in pendingRequests.
Possible causes
-
Typed slot handler not set. When using
init(hostVersion:), ensurehost.documentCapture.handler(orselfieCapture.handler) is set. Without a handler, requests forcamera.document.capturego topendingRequests. -
Action mismatch. For custom capabilities or
BridgeCapabilityHandler, theactionproperty must exactly match the request’spayload.action. Check for typos and case sensitivity. -
Handler not registered. For the
register(handler:)path, ensure it was called before the request arrived. -
Slot is disabled. Check that
isEnabledistrueon the typed slot.
App Transport Security Errors
Symptoms: The WebView shows a blank page or an error. The console shows ATS-related errors. Fix for local development:NSAllowsArbitraryLoads.
WebView Shows Blank Page
Symptoms: The WebView renders but shows nothing.Possible causes
- Invalid URL. Check that the URL is reachable.
- ATS blocking. See above.
- CORS issues. If the journey loads resources from other domains, check CORS headers.
- JavaScript error. Connect Safari Web Inspector to check for console errors.
Memory Warnings or Crashes
Symptoms: App receives memory warnings or crashes when using the bridge.Possible causes
- Large payloads. Sending very large Base64-encoded images through the bridge can cause memory pressure. Consider passing file paths instead of raw data.
- Message accumulation.
receivedMessagesgrows without bound. If you’re in a long-running session, this array can become large.
SwiftUI View Not Updating
Symptoms:BridgeHost state changes (e.g., lastError, receivedMessages) don’t trigger view updates.
Possible causes
- Using
@ObservedObjectwhere@StateObjectis needed. If the view owns the host, use@StateObjectto prevent re-creation on re-renders. - Host created outside the view hierarchy. Ensure the host is referenced via
@StateObjector@ObservedObject.
Typed Slot Returns “BUSY” Error
Symptoms: The web journey receives aBUSY error when sending a capture request.
Cause: A previous capture request is still in progress on the same slot (activeRequest is non-nil).
Fix: Ensure the previous request completes before sending another. Call host.documentCapture.complete(...) when the camera UI finishes or is dismissed. Check the onDismiss closure of your fullScreenCover:
Debugging Checklist
When something isn’t working, run through these checks in whichever order makes most sense for the symptom — they’re independent, not sequential:- Check
host.lastErrorfor error messages. - Check
host.receivedMessagesto see if messages are arriving. - Check
host.pendingRequestsfor unhandled requests. - For typed slots: verify
handleris set andisSupportedistrue. - For typed slots: check
activeRequestisn’t stuck — i.e. a previous request didn’t complete. - Connect Safari Web Inspector to examine the web side.
- Verify handler
actionstrings match request actions exactly. - Ensure the WebView was configured via
BridgeWebVieworBridgeWebViewConfigurator. - Confirm the journey URL is reachable and uses HTTPS.
- Check Info.plist for required permission descriptions.
- Verify
@StateObjectvs@ObservedObjectusage.
Next Steps
- FAQ — Common questions
- Messaging Guide — Message flow details
- Security Guide — Security best practices