WebKit.PrintOperation.print does not work in Flatpak

Stack: GTK4, Webkit 6, Python, Flatpak.

In a Flatpak app, I’m trying to use WebKit.PrintOperation.print_ (the underscore is for the Python bind) to save a page as a PDF. Everything seems to work; the try-except block says the file was saved, but the file isn’t created.

My suspicion is that WebKit.PrintOperation.print_ isn’t correctly handling the portal URI I get via Gtk.FileDialog.

WebKit.PrintOperation.run_dialog exports the file normally after choosing to print to a file. Here is a representative excerpt of the code.

try:

gfile = dialog.save_finish(result)

print_operation = WebKit.PrintOperation.new(self.webview)

uri = gfile.get_uri()

settings = Gtk.PrintSettings()

page_setup = Gtk.PageSetup()

settings.set(Gtk.PRINT_SETTINGS_OUTPUT_FILE_FORMAT, "pdf")

settings.set(Gtk.PRINT_SETTINGS_OUTPUT_URI, uri)

print_operation.set_print_settings(settings)

print_operation.set_page_setup(page_setup)   

print_operation.print_()

…

Hm, Epiphany doesn’t have any trouble with this, but Epiphany notably does not run its own GtkFileDialog.

Just keep in mind the printing happens via a portal, which is probably expecting to receive host paths rather than document portal paths. Still, since document portal paths are accessible on the host system, I would expect it should work regardless. I guess that’s wrong.