feat: opt-in consoleMessage events for openWebView
Merged
RI
2d ago+535+535+012345678901234567890123456789-87-87-01234567890123456789
What
- Document and wire
consoleMessagelistener with payload{ level, message, source?, line?, column? }. - iOS and Android already emit events when
captureConsoleLogs: true; Android level mapping now mapsTIP/WARNINGtoinfo/warn. - Web: same-origin
openWebViewwindows inject a console wrapper and forward logs viapostMessage. Cross-origin pages no-op cleanly. - README usage example, JSDoc/docgen updates, example app already uses this in feature smoke.
Why
- Host apps need page-level diagnostics (especially hidden webviews) without polling or custom bridges.
How
captureConsoleLogsonopenWebView(defaultfalse). When false, no script injection and no extra handlers.- iOS: existing WKUserScript +
consoleMessageHandler. - Android: existing
WebChromeClient.onConsoleMessagewith improved level normalization. - Web:
src/web-console-capture.ts+ installer insrc/web.ts.
Testing
bun run fmtbun run lintbun run buildbun run verify:webbun test src/web-console-capture.test.ts src/web-open.test.ts- Android unit tests extended in
ConsoleMessageEventHelperTest
Not Tested
verify:ios/verify:androidlocally (no SDK/Xcode in cloud VM). CI expected to run full verify.
Opt-in, off by default, no breaking changes.


Need help on this PR? Tag @codesmith-bot with what you need.
Summary by CodeRabbit
-
New Features
- Added console output capture for same-origin pages opened in the in-app browser.
- Captured messages are available through the
consoleMessageevent with normalized log levels and metadata. - Console capture preserves the page’s original console behavior.
-
Bug Fixes
- Assertion messages are reported as errors, while tips and warnings map to informational and warning levels.
- Cross-origin pages ignore the capture option without producing errors.
-
Documentation
- Added a usage example covering listener cleanup and WebView closure, and documented same-origin limitations.