Feat: Add Console bridge for android#372
Merged
KevinnZou merged 2 commits intoSep 30, 2025
Merged
Conversation
-Introduce ConsoleBridge for console log capture (Android Only) and update version
Fix:
Remove tap highlight color in android.
This commit introduces a `ConsoleBridge` to capture console logs from the platform WebView and forward them as JSON payloads.
**JS Bridge:**
- Added `ConsoleBridge.kt` (commonMain) to handle console log capturing. It formats log messages (level, content, source, line number, timestamp) into a JSON string and invokes an `onLog` callback.
- `IWebView.kt` (commonMain): Added `consoleBridge` property. Removed console logging from the default JS bridge script.
- All platform-specific `WebView.platform.kt` and `ActualWebView.kt` implementations now accept and store a `ConsoleBridge?` instance.
- `DesktopWebView.kt`, `IOSWebView.kt`, `WasmJsWebView.kt`: Implemented `consoleBridge` property, returning `null` for now as console capturing is not yet implemented for these platforms.
**Android:**
- `AccompanistWebView.kt`:
- Now accepts a `consoleBridge: ConsoleBridge?` parameter.
- Passes the `consoleBridge` to the `AndroidWebView` instance.
- Implemented `onConsoleMessage` in `AccompanistWebChromeClient` to capture console messages. It formats the message using `ConsoleBridge.emitFromPlatform` if a `consoleBridge` is available.
- Added JavaScript execution to remove the default tap highlight color on Android WebViews for a cleaner user experience.
- Changed `PlatformWebSettings.AndroidWebSettings.LayerType` mapping to use explicit `View.LAYER_TYPE_*` constants.
- `AndroidWebView.kt`: Now accepts and stores a `consoleBridge: ConsoleBridge?`.
- `InternalStoragePathHandler.kt`: Removed debug logging.
**Build:**
- Incremented `VERSION_NAME` to `2.0.4`.
This commit updates the import path for `Res` in `IWebView.kt`. - Changed `import ybee.libs.webview.generated.resources.Res` to `import compose_webview_multiplatform.webview.generated.resources.Res`.
KevinnZou
approved these changes
Sep 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
-Introduce ConsoleBridge for console log capture (Android Only) and update version
Fix:
Remove tap highlight color in android.
This commit introduces a
ConsoleBridgeto capture console logs from the platform WebView and forward them as JSON payloads.JS Bridge:
ConsoleBridge.kt(commonMain) to handle console log capturing. It formats log messages (level, content, source, line number, timestamp) into a JSON string and invokes anonLogcallback.IWebView.kt(commonMain): AddedconsoleBridgeproperty. Removed console logging from the default JS bridge script.WebView.platform.ktandActualWebView.ktimplementations now accept and store aConsoleBridge?instance.DesktopWebView.kt,IOSWebView.kt,WasmJsWebView.kt: ImplementedconsoleBridgeproperty, returningnullfor now as console capturing is not yet implemented for these platforms.Android:
AccompanistWebView.kt:consoleBridge: ConsoleBridge?parameter.consoleBridgeto theAndroidWebViewinstance.onConsoleMessageinAccompanistWebChromeClientto capture console messages. It formats the message usingConsoleBridge.emitFromPlatformif aconsoleBridgeis available.PlatformWebSettings.AndroidWebSettings.LayerTypemapping to use explicitView.LAYER_TYPE_*constants.AndroidWebView.kt: Now accepts and stores aconsoleBridge: ConsoleBridge?.InternalStoragePathHandler.kt: Removed debug logging.Build:
VERSION_NAMEto2.0.4.