feat: opt-in consoleMessage events for openWebView

Merged
RI
2d ago
+535-87

What

  • Document and wire consoleMessage listener with payload { level, message, source?, line?, column? }.
  • iOS and Android already emit events when captureConsoleLogs: true; Android level mapping now maps TIP/WARNING to info/warn.
  • Web: same-origin openWebView windows inject a console wrapper and forward logs via postMessage. 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

  • captureConsoleLogs on openWebView (default false). When false, no script injection and no extra handlers.
  • iOS: existing WKUserScript + consoleMessageHandler.
  • Android: existing WebChromeClient.onConsoleMessage with improved level normalization.
  • Web: src/web-console-capture.ts + installer in src/web.ts.

Testing

  • bun run fmt
  • bun run lint
  • bun run build
  • bun run verify:web
  • bun test src/web-console-capture.test.ts src/web-open.test.ts
  • Android unit tests extended in ConsoleMessageEventHelperTest

Not Tested

  • verify:ios / verify:android locally (no SDK/Xcode in cloud VM). CI expected to run full verify.

Opt-in, off by default, no breaking changes.

Open in Web Open in Cursor 

View with [code]smith Autofix with [code]smith
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 consoleMessage event 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.