Right-click a html file and print it? I've went ahead and created the Automator workflow that let's me have a "print this file" right-click menu in Finder.

It works fine for pdf and txt files, but if I try the same on a html file, the printer spits out a blank page. Obviously the file needs to be rendered by a browser first, then printed, but is there a way to do this?

It's not an option for me to convert this to pdf, the contents of the document are randomized with javascript. I would want to preserve this, I do not want identical content to print every time.

If this could be added to the same right-click menu item, that would be good. If it has to open Safari in the background or something like that, that's not a dealbreaker, though I'd like for it to close itself after printing.

Chrome is the default browser (and almost always open) if that matters.
This is pretty easy to do through automator and the "Watch me do" actions. Here's what I got to work however you'd likely replace your input with however you're getting the file in your setup



Display Webpages opens the HTML file in the default browser (in this case chrome) and then we enter Command-P and then Enter which brings up the print dialog and then prints with the default settings because the print button is the initial highlighted button. This will work with whatever fancy javascript you've got and you can optionally add a wait period between launching the file and sending the print keys to allow it to fully render/load.