Log WebView load errors when exporting a note to PDF#1037
Conversation
📝 WalkthroughWalkthrough
ChangesPDF WebView Error Logging
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/src/main/java/android/print/PdfExtensions.kt`:
- Line 35: The Log.w call that logs "PDF WebView load error" currently includes
the raw failingUrl (in PdfExtensions.kt, the Log.w(TAG, "... $failingUrl")
line); change it to sanitize the URL before logging by parsing the failingUrl
with java.net.URI (or android.net.Uri) and logging only the host and path (or
scheme://host/path) while stripping query and fragment (or fallback to a
redacted placeholder if parsing fails), then use that sanitized string in the
Log.w message instead of the full failingUrl.
- Around line 28-36: The WebView error handler only overrides the deprecated
4-arg onReceivedError (main-frame only) so subresource failures on API 23+ are
missed; add the API‑23+ override onReceivedError(view: WebView?, request:
WebResourceRequest?, error: WebResourceError?) alongside the existing
onReceivedError(view: WebView?, errorCode: Int, description: String?,
failingUrl: String?) and route both to a shared logger method (e.g.,
logWebViewError(...) or a private logError function that accepts
code/description/url and uses TAG) so all errors (main-frame and subresource)
are logged; keep `@Suppress`("DEPRECATION") on the 4-arg override and use
request?.url?.toString() and error?.errorCode/error?.description where
appropriate to populate the shared logger.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 95a5ed7b-12a7-4257-9b99-ae7cc5ae1248
📒 Files selected for processing (1)
app/src/main/java/android/print/PdfExtensions.kt
|
LGTM, thanks :) |
Closes #1036
What this does
Adds a single
onReceivedError(view, errorCode, description, failingUrl)override to theWebViewClientused inContext.printPdf(...)inapp/src/main/java/android/print/PdfExtensions.kt. It logs the error code, description and failing URL withLog.w. Adds a small file-levelprivate const val TAG = "PdfExtensions".No behaviour change in the happy path. No new dependencies.
Why
onPageFinishedcurrently fires regardless of whether the load succeeded, so a print that ended up with missing assets ships throughcreatePrintDocumentAdapter(...)and produces a half-rendered PDF with no logcat trace. This override makes the failure visible so future "exported PDF is missing parts" reports have something concrete to look at.Note on the signature
I used the deprecated 4-arg form rather than the API 23+
(WebView, WebResourceRequest, WebResourceError)overload on purpose. The app'sminSdkis 21 and the framework dispatches the deprecated form on every API level when nothing else is overridden, so this single override actually fires for every user. Happy to switch to the new signature gated onBuild.VERSION.SDK_INT >= Mif you would prefer that style.Summary by CodeRabbit