chromiumembedded / cef

Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.
https://bitbucket.org/chromiumembedded/cef/
Other
3.38k stars 467 forks source link

Off screen renderer fails to export sandboxes iframes to pdf #3798

Closed ebrandin closed 1 month ago

ebrandin commented 1 month ago

Describe the bug Starting from CEF 125, PrintToPDF fails when trying to render sandboxed iframes. It does however work if the sandbox attribute is set to "allow-script allow-same-origin".

The CefPdfPrintCallback is never invoked due to CefPdfPrintCallbackCToCpp::OnPdfPrintFinished being called with empty path, which makes our application hang on export to pdf.

To Reproduce

  1. Apply the provided patch
  2. Run the unit tests (--gtest_filter=OSRTest.PrintToPdf*) (may also require --disable-features=PrintCompositorLPAC)
  3. All provided tests except one passes. The last, with attribute sandbox="allow-scripts" fails with "Printing failed"
    [1007/133205.422:WARNING:browser_info.cc(345)] Returning a speculative frame for [12,5]
    [1007/133205.422:WARNING:browser_info.cc(345)] Returning a speculative frame for [12,5]
    [1007/133205.423:WARNING:browser_info.cc(345)] Returning a speculative frame for [12,5]
    [1007/133205.423:WARNING:browser_info.cc(345)] Returning a speculative frame for [12,5]
    [1007/133205.555:WARNING:browser_info.cc(345)] Returning a speculative frame for [12,5]
    C:\Source\github\cef-project\third_party\cef\cef_binary_127.3.4+ge9e2e14+chromium-127.0.6533.100_windows64\tests\ceftests\test_handler.cc(556): error: Value of: false
    Actual: false
    Expected: true
    Test timed out after 5000ms
    [1007/133210.329:ERROR:print_util.cc(40)] PrintToPDF failed with error: Printing failed
    [1007/133210.330:FATAL:pdf_print_callback_ctocpp.cc(34)] Check failed: !path.empty().

Expected behavior All unit tests should pass, rendering all versions of the sandboxed iframes.

Versions (please complete the following information):

Additional context This used to work up to version 124.

Does the problem reproduce with Google Chrome at the same version? No, Chrome is able to export sandboxed iframes to pdf.

Add any other context about the problem here. iframe_to_pdf.patch

jasminjasmin2 commented 1 month ago

I could also reproduce this issue. It seems somehow related to bug #3768 . The behavior is very similar. However, I could not find any evidence of sandbox iframe usage in www.corriere.it website which cannot be printed to PDF .

Should it matter if the application is built with or without sandbox enabled? In my tests reproduces in both situations if did not do anything wrong.

I also could not find any Chromium command line switch to force the allow-scripts and allow-same-origin for sandbox frames.

ebrandin commented 1 month ago

It seems somewhat related to #3768. In that issue I was able to get a print preview when all iframes were removed (using dev tools). Those removed iframes were not sandboxed, but since they had another origin both issues might be related to site isolation.

In CEF 130.0.3 (beta), the #3768 issue seems to be fixed. However, my issue regarding sandboxed iframes is still reproducible.

magreenblatt commented 1 month ago

Likely fixed with #3768. Please report back if it isn't.

handerss-spotfire commented 4 weeks ago

Fix for #3768 does indeed fix the issue, thanks @mbragg12 and @magreenblatt!