Skip to content

Feat: Add Console bridge for android#372

Merged
KevinnZou merged 2 commits into
KevinnZou:mainfrom
amirghm:feature/add-console-bridge-for-android
Sep 30, 2025
Merged

Feat: Add Console bridge for android#372
KevinnZou merged 2 commits into
KevinnZou:mainfrom
amirghm:feature/add-console-bridge-for-android

Conversation

@amirghm

@amirghm amirghm commented Sep 28, 2025

Copy link
Copy Markdown
Contributor

-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.

-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 KevinnZou merged commit 209fac7 into KevinnZou:main Sep 30, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants