Skip to content

feat(android): Add a WebView loadUrl adapter for the Sentry Android Gradle Plugin - #6592

Open
antonis wants to merge 3 commits into
mainfrom
feat/webview-trace-propagation-adapter
Open

antonis wants to merge 3 commits into
mainfrom
feat/webview-trace-propagation-adapter

Conversation

@antonis

@antonis antonis commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

📜 Description

Adds SentryWebViewTracingAdapter, an internal class that the Sentry Android Gradle Plugin calls in place of WebView.loadUrl (getsentry/sentry-android-gradle-plugin#1505). It refreshes the trace propagated to the page, then calls the original loadUrl:

  • Only http(s) URLs trigger a refresh, so javascript: URLs are left alone.
  • It uses the hosts the app passed to addTracePropagation for that WebView, or else webViewTracing.allowedHosts from the options, so a WebView the app limited to specific hosts isn't widened to the app-wide list.
  • Without hosts, or off the WebView's thread, it does nothing and keeps any script the app installed.
  • Failures are logged and fatal errors rethrown, except LinkageError from a missing or outdated androidx.webkit. The load always happens.
  • The refresh doesn't count as manual adoption (WebViewTracePropagation), since the plugin reports its own WebViewInstrumentation feature, and it warns about a missing androidx.webkit only once.

The plugin calls this adapter rather than SentryWebViewTracing.addTracePropagation(webView) directly, because that method removes the existing script when no hosts are set and can throw into the app's code. The adapter keeps a script the app installed, and never changes how the load behaves.

💡 Motivation and Context

Part of #6407

💚 How did you test it?

Unit tests for the adapter and the refresh.

End to end, with a local build of the plugin and the sample app on an emulator (Pixel 8, API 37). The sample's WebView, a subclass, had no manual addTracePropagation call. The plugin rewrote its loadUrl call, and the page joined the app's trace:

With the plugin's WebView feature turned off, the page received no trace.

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed docs(android): Document automatic WebView trace propagation with the Gradle plugin sentry-docs#20751
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

…radle Plugin

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 633c585

@sentry

sentry Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.64.0 (1) release

⚙️ sentry-android Build Distribution Settings

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

…rror

Also keeps the automatic refresh out of the manual adoption count, warns
about a missing androidx.webkit only once, and documents that the refresh
keeps explicitly passed hosts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 633c585. Configure here.

@antonis
antonis marked this pull request as ready for review November 12, 2026 10:52
@antonis
antonis requested review from a team and adinauer as code owners November 12, 2026 10:52
@antonis
antonis requested review from markushi and runningcode and removed request for a team November 12, 2026 10:52

This branch has not been deployed

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

1 participant