Browser will not print phoenix liveview page rendered


I have a liveview which needs to be printable from the browser, but it is finicky in that it often will not let me print. When I open the print module (cmd + p or via the file menu), the print window opens but crashes without fully loading after a few seconds. The browser window itself does not crash, however. I’ve noticed that if I try to print immediately after loading the view, it seems to work. But if I use any of the phx-clicks in the view, it will no longer print.

I’m observing this in both Chrome and FF.

My deps:
{:phoenix, “~> 1.6.6”},
{:phoenix_ecto, “~> 4.4.0”},
{:phoenix_html, “~> 3.0”},
{:phoenix_live_reload, “~> 1.2”, only: :dev},
{:phoenix_live_view, “~> 0.17.7”},

Does anyone have any advice they can provide? I’m not having any luck with our good friend google.

Thank you very much

I have not seen the “print window crash” but I know (at least earlier this year) on windows x chrome, the print dialog would suspend network traffic or the JS engine and the LV would disconnect, so you need to have any reconnect-recovery code sorted out.

Do you mean the actual OS “pick your printer and paper size” window … automatically closes? Shows an error message? I guess you are on macOS by the cmd-p language.

I have never had issues printing a LV (~0.18, 0.19?, not tested 0.20 in production) and some of my applications print lots of things different views. :person_shrugging:

I wonder if your “print immediately” is printing before the websocket connects? I would at least try printing with the connection disabled to see if its some quirk there. Does the behaviour change when you navigate to the page when already connected, vs refreshing it?

1 Like

Hi Soup,
Thank you very much for the assist. I’m sorry for the delayed reply… we’ve been through it the past month and this fell out of mind.

Correct, I hit cmd+p to print and the OS print dialogue starts to open but disappears. There is no error message. I can print this elixirforum page just fine with this method. But on my app the print window disappears while trying to load.

I definitely do not have lv reconnnect-recovery code sorted. So I’ll focus there to start. I’ve read about that in the past and did not feel like I understood or handled. If you know of a good ref and can point me to it, much appreciated.

Thank you very much again!

I upgraded my LV from 0.17 to 0.18.18 and phx to 1.7 and the print problem is now resolved.

Thank you for taking a look at it and the direction. Researching methods for handling disconnections in LV prompted me to upgrade LV and I’m still planning to implement the rest of the strategy despite the print bug fix. Thank you