Log WebView load errors during PDF export#170
Open
jim-daf wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
Adds a single
onReceivedError(view, errorCode, description, failingUrl)override to theWebViewClientused byPostPDFGenerator.create(...)inapp/src/main/java/android/print/PostPDFGenerator.kt. It logs the error code, description and failing URL withLog.w. Adds a small file-levelprivate const val TAG = "PostPDFGenerator".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.