Closed Bug 1970805 Opened 9 months ago Closed 8 months ago

HTML Spec page fails to print to PDF

Categories

(Core :: Printing: Output, defect, P3)

Desktop
All
defect

Tracking

()

VERIFIED FIXED
142 Branch
Tracking Status
firefox-esr128 --- unaffected
firefox-esr140 --- verified
firefox139 --- wontfix
firefox140 --- wontfix
firefox141 --- wontfix
firefox142 --- verified

People

(Reporter: csasca, Assigned: jfkthame)

References

(Regression)

Details

(Keywords: regression)

Attachments

(4 files)

Attached image print preview error.png

Found in

  • Firefox 140.0b5

Affected versions

  • Firefox 140.0b5
  • Firefox 141.0a1

Tested platforms

  • Affected platforms: All

Steps to reproduce

  1. Access this page
  2. Open the print preview and wait for the preview to fully load
  3. Print the page to PDF

Expected result

  • The page is printed

Actual result

  • A brief message appears stating "An error occurred while printing" is shown and the output file is corrupt and cannot be opened

Regression range

  • Looked for regression and it seems that this was introduced between 2024-12-04 and 2024-12-05. Bug 1929461 was shown in the pushlog.

Additional notes

  • The issue can be seen in the attachments
  • Print preview will take some time to be shown as there are ~1000 pages to load
  • Browser console will throw some errors as well.
Keywords: regression
Regressed by: 1929461

Set release status flags based on info from the regressing bug 1929461

:jfkthame, since you are the author of the regressor, bug 1929461, could you take a look? Also, could you set the severity field?

For more information, please visit BugBot documentation.

Flags: needinfo?(jfkthame)
Component: Printing → Printing: Output
Product: Toolkit → Core
Severity: -- → S3
Priority: -- → P3

Interesting.... I was able to confirm that on macOS, with a build from 2024-12-04 I get a successfully-generated PDF, while with 2024-12-05 it is truncated/broken. However, on Windows it is broken both before and after that date; neither build creates a usable PDF.

The patch in bug 1929461 only changes behavior if we get a DrawTarget that is marked as Invalid; so I guess that must be happening here, but prior to bug 1929461 we were ignoring the error, and it was not actually fatal on macOS (whereas in some other cases it could result in a crash, which is what we wanted to avoid).

Flags: needinfo?(jfkthame)

Set release status flags based on info from the regressing bug 1929461

Do we want to fix this regression for 141? Thanks

Flags: needinfo?(jfkthame)

I think the odds are against it at the moment. We need a better understanding of the error condition that's arising than we currently have, and debugging this is likely to be a slow process. :(

Flags: needinfo?(jfkthame)

Weird -- today, I'm not able to reproduce the failure on Windows at all; it's successfully generating a complete 998-page PDF. I first tried with my local Nightly build, intending to try and narrow down the issue, but it succeeded. So then I used mozregression to try builds from 2024-12-04/05 (compare comment 3), and these also succeeded, despite having failed last week. What's changed? I don't know.

The issue does reproduce for me on macOS, so I'm trying to get some insight into what's happening...

It seems that we're getting an error (returned as "out of memory" by cairo, though I think this is misleading -- the real issue is an unexpected CGContext type) inside cairo from _cairo_quartz_surface_map_to_image, which then propagates up to the cairo context and results in the DrawTarget becoming invalid. This causes Recorded{whatever}::PlayEvent to return false, and the playback of the recording bails out.

(In the case of the big HTML spec, checking the output from a "working" version (prior to bug 1929461), I notice that some content is missing from section 4.8.4.1, including the "magnifying-glass" superimposed on the mobile-screen image examples. I'm guessing it may be the pattern fill within the SVG image that's triggering an error condition in the cairo-quartz backend, though I have not yet specifically verified this.)

To handle this better, we should not entirely abort playback if the DrawTarget's context is in an error state; instead, we can just skip attempting to do any actual drawing operations to it -- to avoid issues like the crash in bug 1929461 -- but allow playback to continue. This may result in some content missing from the output, but is better than failing to generate a valid PDF at all.

Assignee: nobody → jfkthame
Status: NEW → ASSIGNED
Attachment #9496963 - Attachment description: Bug 1970805 - Don't bail out of print-job playback if the cairo context is in an error state; just stop drawing to this context, but allow the job to continue. r=#gfx-reviewers → Bug 1970805 - Remove validity check from Translator::GetCurrentDrawTarget to avoid aborting print-job playback, and add drawtarget-validity checks to more methods in DrawTargetCairo. r=#gfx-reviewers
Pushed by jkew@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/6993cdd7e2af https://hg.mozilla.org/integration/autoland/rev/ac7e098bc5b1 Remove validity check from Translator::GetCurrentDrawTarget to avoid aborting print-job playback, and add drawtarget-validity checks to more methods in DrawTargetCairo. r=gfx-reviewers,lsalzman,jrmuizel
Pushed by sstanca@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/79396de8796d https://hg.mozilla.org/integration/autoland/rev/5bfd1afd5ca1 Revert "Bug 1970805 - Remove validity check from Translator::GetCurrentDrawTarget to avoid aborting print-job playback, and add drawtarget-validity checks to more methods in DrawTargetCairo. r=gfx-reviewers,lsalzman,jrmuizel" for causing wpt assertion failures in PrintTranslator.h.

Reverted this because it was causing wpt assertion failures in PrintTranslator.h.

Flags: needinfo?(jfkthame)
Pushed by jkew@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/e0b19141c9ef https://hg.mozilla.org/integration/autoland/rev/57ca0dcab3ca Remove validity check from Translator::GetCurrentDrawTarget to avoid aborting print-job playback, and add drawtarget-validity checks to more methods in DrawTargetCairo. r=gfx-reviewers,lsalzman,jrmuizel
Status: ASSIGNED → RESOLVED
Closed: 8 months ago
Resolution: --- → FIXED
Target Milestone: --- → 142 Branch
Flags: needinfo?(jfkthame)

I've verified that the issue is fixed on Firefox 142.0a1 (2025-07-20) on macOS 15.5.

It seems though that Ubuntu 24.04 and Windows 11 will print the file, but I was able to open them only on Chrome. I tried Firefox and Edge on Windows and they wouldn't open the printed PDF, and on Ubuntu I tried the system document reader and Firefox and still no luck.

I'll mark this as verified on 142 as the files are printed, but should I file a new issue for the windows/ubuntu thing?

QA Whiteboard: [qa-found-in-b140] → [qa-found-in-b140][qa-ver-done-c142/b141]
Flags: needinfo?(jfkthame)
QA Contact: csasca

It may be that the file is so big that it's exceeding some limitation in pdf.js, but seems worth at least looking into it. So a new issue (in the PDF Viewer component) sounds like the right way forward.

Flags: needinfo?(jfkthame)

Logged Bug 1978317 as a follow up. Thanks!

Duplicate of this bug: 1976450

Should we uplift this to ESR140 also? Please nominate if yes.

Flags: needinfo?(jfkthame)

Yes, I think we should uplift to esr140. We should probably consider taking the followup bug 1978317 as well, although the situation that's addressing (wallpapering, really) is more extreme edge-caseish.

Flags: needinfo?(jfkthame)
Attachment #9508369 - Flags: approval-mozilla-esr140?

firefox-esr140 Uplift Approval Request

  • User impact if declined: A cairo error condition during printing (e.g. some kind of content it can't handle) results in print failure / broken PDF output
  • Code covered by automated testing: yes
  • Fix verified in Nightly: yes
  • Needs manual QE test: yes
  • Steps to reproduce for manual QE testing: Load the big HTML spec https://html.spec.whatwg.org/ and print to the Save to PDF destination
  • Risk associated with taking this patch: low
  • Explanation of risk level: Patch just moves error-handling so that an error state on one page doesn't abort the entire job
  • String changes made/needed: none
  • Is Android affected?: yes
Flags: qe-verify+
Attachment #9508369 - Flags: approval-mozilla-esr140? → approval-mozilla-esr140+

I'm not able to reproduce this bug using an affected Nightly build (2025-06-06) on Win 11 and macOS 15.

I think we need to wait until my colleague, Catalin, returns from PTO since he was able to reproduce it on his machine.

Verified that the page is printed to PDF without issues on Firefox ESR 140.3.1. Tests were performed on macOS 26.0, Windows 11 and Ubuntu 24.04.

As a note, it took a very very long time for the file to be printed to PDF on Windows 11 (by comparison with Mac and Ubuntu), but eventually it finishes the job and the file can be opened without issues.

Status: RESOLVED → VERIFIED
Flags: qe-verify+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: