Closed Bug 1962075 Opened 19 days ago Closed 10 days ago

[Android] Share | Save-as-PDF fails to save a file (reported as "Download Completed (0.00 KB)" but really no file gets generated)

Categories

(Firefox for Android :: Downloads, defect)

Firefox 137
defect

Tracking

()

RESOLVED FIXED
140 Branch
Tracking Status
firefox137 --- wontfix
firefox138 --- fixed
firefox139 --- verified
firefox140 --- verified

People

(Reporter: tfpbcd, Assigned: npoon)

References

(Regression)

Details

(Keywords: regression, Whiteboard: [fxdroid] [group4])

Attachments

(6 files)

Clone of https://bugzilla.mozilla.org/show_bug.cgi?id=1949200
I cannot reopen the original bug.
I tested on multiple android phones.

Steps to reproduce:

Firefox share page > Save as PDF
Confirm the size of the document is 0 byte
Confirm that there is no file saved on the phone

Actual results:

The Firefox can only print "Zero Bytes" PDFs for several months

Expected results:

Normal PDFs should be printed out with contents and should be able to be opened by Preview

Flags: needinfo?(dholbert)

Thanks, I can reproduce that. (It's good that we didn't reopen bug 1949200, since this is a different underlying issue from what was happening there; the reporter in that bug was dependent on a particular extension to trigger the issue, and that's not the case here.)

Regression range, bisecting Firefox-for-Android Nightly builds with mozregression:
Newest known good nightly: 2025-02-03
Oldest known bad nightly: 2025-02-04
Pushlog: https://hg-edge.mozilla.org/mozilla-central/pushloghtml?fromchange=29c957dc0c6f&tochange=1a07567906ae

Status: UNCONFIRMED → NEW
Component: Printing: Output → General
Ever confirmed: true
Flags: needinfo?(dholbert)
Product: Core → Firefox for Android
Summary: Malfunctioning on [ Default Printing > Save as PDF ] → [Android] Share | Save-as-PDF fails to save a file (reported as "Download Completed (0.00 KB)" but really no file gets generated)

Given that this was an Android-specific regression and it broke save-as-PDF for every page (rather than for particular special bits of pathological content), I'm suspicious that this would be some sort of Android-specific change.

In the pushlog, bug 1912455 looks like a possible culprit - it's about file-downloads and specifically about an edge-casey scenario when a download reaches 100%, and in this case save-as-PDF represented as a PDF that ~instantly jumps to 100%, so maybe it's

I don't know that code, but I do notice that it added an early-return from performDownload, to make us bail out if we happen to get a call to that function when we've reached 100%.

Assuming that save-as-PDF actually exercises that code, I wonder if maybe we're running into trouble because the early-return is preventing us from getting to some important piece that has to happen at least once, later in the function?

npoon, it looks like you've got some experience with file downloads and save-as-PDF - maybe you could take a look here?

Flags: needinfo?(npoon)

The Bugbug bot thinks this bug should belong to the 'Firefox for Android::Downloads' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: General → Downloads

I think more generally, actual zero-byte downloads are broken entirely right now, too - they don't generate any file at all on your filesystem, likely due to this same bug.

STR:

  1. Click this link (or paste it into your URLbar and submit): https://dholbert.org/zero.zip (this is just an 0-byte empty file)
  2. Click through any UI to confirm that you'd like to download the file.
  3. Open your Android file-explorer program (e.g. "Files" on pixel phones) to check for the file in your downloads folder.

ACTUAL RESULTS:
No such file.

EXPECTED RESULTS:
File should be there. (with a size of 0 bytes)

Firefox Nightly gives ACTUAL RESULTS.
Chrome gives EXPECTED RESULTS. (It shows "download error" in the system tray, presumably because it assumes that the 0-byte file size means that something went amiss, but in fact it does successfully "download" the 0-byte file and generate a file on my filesystem.)

I think this^ bug and the PDF bug are versions of the same issue -- files that download ~instantly don't actually get created, possibly because they never get beyond the very start of performDownload as hypothesized above.

Duplicate of this bug: 1958913
Duplicate of this bug: 1960191
Duplicate of this bug: 1961554
Duplicate of this bug: 1958873

Thanks for flagging this Daniel! I will add this bug into our next sprint and if I don't take a look at it, someone else on my squad will :)

Flags: needinfo?(npoon)
Whiteboard: [fxdroid][group4]
Severity: -- → S2
Whiteboard: [fxdroid][group4]
Whiteboard: [fxdroid] [group4]
Assignee: nobody → npoon
Status: NEW → ASSIGNED

Hey Daniel,
When you were bisecting this with moz-regression, did you try to open the file (from save as PDF) after a successful download. I tried removing the early return and I see that the prompt shows that the webpage pdf downloads successfully but upon opening the file, it can't be displayed

Flags: needinfo?(dholbert)

Yes - Nightly 2025-02-03 (last good build from comment 1) generates a PDF file that opens just fine.

Flags: needinfo?(dholbert)

For reference: here's a screencast captured from mozregression-launched Nightly 2025-02-04, showing the "bad" results.

Attachment #9481315 - Attachment description: screencast of bad results in Nightly 2025-04-04 → screencast of bad results in Nightly 2025-02-04

For reference: here's a screencast captured from mozregression-launched Nightly 2025-02-03, showing the "good" results -- notably:

  • Nonzero size reported for the PDF file
  • The generated PDF successfully opens in Firefox Nightly when I tap through the "Download completed" toast.
  • The generated PDF shows up in my file viewer application and successfully opens in a 3rd-party PDF viewer when I tap to open it there.

(Note, my Downloads folder was empty when I started this screen recording, so the PDF that ends up being listed there really is the one that this Nightly generated during the screencast.)

I can confirm the Bug (using Firefox 137.0.2) as described here.

A workaround that works for me on a Samsung phone:
Open a website (wikipedia.org), then in the ⋮-Menu tap on "🖨️ Print" and select "Save as PDF" as printer, then tap the yellow ⤓PDF-Button.

The workaround works for me too, thanks Chris. W!

Just did some investigation. We have multiple issues here.

  1. Save as PDF results in 0B and PDF is not shown in downloads directory. This issue was regressed by Bug 1912455 in Fx 137.
  2. PDF is malformed when being saved through Save as PDF or Print. This issue was regressed since Fx 139. I ran a moz-regression with the following results:
    Newest known good nightly: 2025-04-14
    Oldest known bad nightly: 2025-04-15
    a. If trying to save as PDF, you will not be able to open the saved file (through fenix or external application) because the PDF is malformed
    b. If trying to print PDF, android will open the print page. It will try to generate a preview of the page. This is not possible because of the malformed PDF so the app will then crash with java.lang.RuntimeException: Cannot print a malformed PDF file

Note that bug 1961443 is currently being tracked as an Android topcrash at the moment.

See Also: → 1961443

I have found the regression of issue number 2 from comment 16. Setting the regression fields to reflect this - Bug 1841946.

I can fix issue 1 but I'm not as familiar with toolkit. Can the author of the regressor take a look please?

Flags: needinfo?(sguelton)
Keywords: regression
Regressed by: 1841946, 1912455

We need two bugs for the two issues. Will this bug be about issue 1 or issue 2?

We also need a test that would have caught issue 2.

Thanks for calling this out Markus! I was thinking about a test for issue 2 as well. I will file this soon.

Let's make this bug about issue 1 and Bug 1961443 can be about issue 2 then

Flags: needinfo?(sguelton)
No longer regressed by: 1841946

(In reply to Markus Stange [:mstange] from comment #20)

We also need a test that would have caught issue 2.

I addressed this over in Bug 1961443 since this focuses on issue 2

Pushed by npoon@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/b8047f258cb3 Fetch download even if content length is equal to current bytes copied r=android-reviewers,rsainani
See Also: → 1963821
See Also: → 1963827

Comment on attachment 9484389 [details]
Bug 1962075 - Fetch download even if content length is equal to current bytes copied

Beta/Release Uplift Approval Request

  • User impact if declined/Reason for urgency: Users won't be able to save webpages as PDFs. There have been lots of complains about this on the Google Play store.
  • Is this code covered by automated tests?: No
  • Has the fix been verified in Nightly?: No
  • Needs manual test from QE?: Yes
  • If yes, steps to reproduce: 1. Go to wikipedia.org
  1. Click the share icon
  2. Click save as PDF
  3. Download the PDF
  4. Open the PDF and verify that it can be opened
  • List of other uplifts needed: None
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky):
  • String changes made/needed:
  • Is Android affected?: Yes
Attachment #9484389 - Flags: approval-mozilla-beta?
Flags: qe-verify+

firefox-beta Uplift Approval Request

  • User impact if declined: Users won't be able to save webpages as PDFs. There have been lots of complains about this on the Google Play store.
  • Code covered by automated testing: no
  • Fix verified in Nightly: no
  • Needs manual QE test: yes
  • Steps to reproduce for manual QE testing: Go to wikipedia.org. Click the share icon. Click save as PDF. Download the PDF. Open the PDF and verify that it can be opened
  • Risk associated with taking this patch: Low
  • Explanation of risk level: The feature is already broken on beta
  • String changes made/needed: N/A
  • Is Android affected?: yes

firefox-release Uplift Approval Request

  • User impact if declined: Users won't be able to save webpages as PDFs. There have been lots of complains about this on the Google Play store.
  • Code covered by automated testing: no
  • Fix verified in Nightly: no
  • Needs manual QE test: yes
  • Steps to reproduce for manual QE testing: Go to wikipedia.org. Click the share icon. Click save as PDF. Download the PDF. Open the PDF and verify that it can be opened
  • Risk associated with taking this patch: Low
  • Explanation of risk level: The feature is already broken on release
  • String changes made/needed: N/A
  • Is Android affected?: yes

Just closing the loop here, it turns out that issue 2 only happens on certain websites. It's only for FT fonts

firefox-release Uplift Approval Request

  • User impact if declined: Users won't be able to save webpages as PDFs. There have been lots of complains about this on the Google Play store.
  • Code covered by automated testing: no
  • Fix verified in Nightly: no
  • Needs manual QE test: yes
  • Steps to reproduce for manual QE testing: Go to wikipedia.org. Click the share icon. Click save as PDF. Download the PDF. Make sure that the download completed dialog shows a file size that isn't 0B. Open the PDF and verify that it can be opened
  • Risk associated with taking this patch: Low
  • Explanation of risk level: The feature is already broken on release
  • String changes made/needed: N/A
  • Is Android affected?: yes

firefox-beta Uplift Approval Request

  • User impact if declined: Users won't be able to save webpages as PDFs. There have been lots of complains about this on the Google Play store.
  • Code covered by automated testing: no
  • Fix verified in Nightly: no
  • Needs manual QE test: yes
  • Steps to reproduce for manual QE testing: Go to wikipedia.org. Click the share icon. Click save as PDF. Download the PDF. Make sure that the download completed dialog shows a file size that isn't 0B. Open the PDF and verify that it can be opened (depends on Bug 1961443)
  • Risk associated with taking this patch: Low
  • Explanation of risk level: The feature is already broken on beta
  • String changes made/needed: N/A
  • Is Android affected?: yes
Attachment #9484853 - Flags: approval-mozilla-beta+
Attachment #9484389 - Flags: approval-mozilla-beta?
Status: ASSIGNED → RESOLVED
Closed: 10 days ago
Resolution: --- → FIXED
Target Milestone: --- → 140 Branch

Verified as fixed on the latest Firefox Beta 139.0b3, and on Nightly 140.0a1.
Tested with Xiaomi Mi8 Lite 9Android 10), Google Pixel 6 (Android 16), and Samsung Galaxy Tab S9 Ultra (Android 14).
Saving a Wikipedia page as a PDF is working correctly. The downloaded PDF can be opened without issues.

Duplicate of this bug: 1962157
Duplicate of this bug: 1961180
Attachment #9484856 - Flags: approval-mozilla-release?
Attachment #9484856 - Flags: approval-mozilla-release? → approval-mozilla-release+
Flags: in-testsuite+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: