Having a print-friendly CSS issue with Chrome and IE/MS Edge browsers… images in the page won’t render in the print preview dialog, but canceling out and immediately trying to print again (CTRL + P) the images will show up.
Images will render in Mozilla Firefox on first try every time, however.
It happens with any Win10 machine using Chrome or IE.
So… doing a simple CTRL+P to print from these browsers, the first attempt will show all the text on the page, but no image (which is a standard PNG in this case). However, immediately cancelling the print dialog/preview, and hitting CTRL+P again, the image will render properly.
Firefox print preview renders the image immediately. IE and Chrome will only render it only on successive attempts.
Is there a specific reason you believe it to be a CSS issue? Does it work without the CSS print stylesheet?
As said, without an example it’s a little hard to say much. But off the top of my head, I’m not really aware of any issue with the two browsers that would cause this. Have you tried searching for this issue?
…but that image isn’t actually included anywhere in the web page, since this is only for printing.
Kind of strange, however. Other images actually in the web pages will print. So I’m guessing that these two browsers don’t like my CSS… at least on the first try when hitting CTRL+P.
Mannn, I wish that worked, but still the same. Cleared browser cache on multiple machines… same behavior.
Thinking I need to retool this CSS, or somehow include the image in the HTML of the web page without actually showing it in the web page, haha. Because display:none in my global stylesheet would still hide it from my print.css stylesheet.
I didn’t actually test it with a pseudo-element, sorry I totally missed that part. I can still reproduce this issue using a pseudo-element. In Firefox I don’t see the image getting fetched at all, but it still works. In Chrome, I see the fetch happen when you Ctrl + P but it doesn’t show up on the print page preview.
BTW, I didn’t try printing but I assume it is missing on the printed page and not just the preview?
(In my tests (in Chrome) ](Background Image Print Test) the image is not loaded the first time you try and print the page. If you try a second time then the image appears.
The image seems to need to be in cache before the print is selected. The only way I can see that that will happen is by loading it by default in the main stylesheet and hiding it offscreen and then just revealing it in the print stylesheet. This of course means the image is loaded when it may never be needed."
Kind of sad that thread is from 2016. I guess no one has reported this issue. Or it’s working as intended (spec-compliant). Although personally, I believe it’s a bug.
I will let you know if I figure something else out. But for now, it seems the images have to be fetched (I guess cached), either loaded in the HTML and hidden, or using preload.
I don’t think there is a CSS fix for this. The resource is literally missing at the time of the preview, the preview causes the resource to be fetched but it’s too late. Or the preview relies on cached resources.
Right on, man. The behavior that it won’t show the first time is odd, since Firefox handles it with no problem. Anyway, I added this in a template file…